@apet97/clockify-cli-115 0.6.1 → 2.0.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.
package/README.md CHANGED
@@ -3,8 +3,8 @@
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: `0.6.1`. Requires Node.js `>=22.13.0` and
7
- `clockify-sdk-ts-115 >=0.15.1 <1`.
6
+ Current release: `2.0.0`. Requires Node.js `>=22.13.0` and
7
+ `clockify-sdk-ts-115 ^2`.
8
8
 
9
9
  Two binaries, identical behavior:
10
10
 
@@ -74,12 +74,13 @@ touching production credentials.
74
74
  `--select 0.name`) before emitting JSON or NDJSON.
75
75
 
76
76
  In `json` and `ndjson` modes, errors go to stderr as `{"ok": false, "error":
77
- "...", "code": "...", "recovery": "...", "retryable": true|false}`; success-only
78
- commands emit `{"ok": true, "message": "..."}`. `--no-color` disables ANSI
79
- codes, and the CLI also auto-disables color when stdout is not a TTY.
77
+ "...", "code": "...", "recovery": "...", "retryable": true|false}`.
80
78
  Successful write commands in JSON and NDJSON include receipt fields:
81
79
  `ok`, `action`, `entity`, `ids`, `changed`, `warnings`, and `next`.
82
80
  Legacy top-level fields such as `id` remain for simple shell scripts.
81
+ Read-only commands (e.g. `status`, `entries list`) print the requested
82
+ object or array directly, with no `ok` wrapper. `--no-color` disables
83
+ ANSI codes, and the CLI also auto-disables color when stdout is not a TTY.
83
84
 
84
85
  ## Commands
85
86
 
@@ -239,7 +240,7 @@ node dist/index.js status # smoke test (or invoke installed clk115/clockify11
239
240
  ```
240
241
 
241
242
  `clockify-sdk-ts-115` is workspace-linked for local development and is a
242
- `>=0.15.1 <1` peer dependency for published consumers.
243
+ `^2` peer dependency for published consumers.
243
244
 
244
245
  ## License
245
246
 
package/dist/client.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { requireApiKey } from "./config.js";
2
- const REGIONAL_PREFIXES = ["eu", "us", "uk", "au"];
3
- const KNOWN_REGIONS = ["global", ...REGIONAL_PREFIXES, "developer"];
2
+ export const REGIONAL_PREFIXES = ["eu", "us", "uk", "au"];
3
+ export const KNOWN_REGIONS = ["global", ...REGIONAL_PREFIXES, "developer"];
4
4
  export function buildRoutingOptions(region, subdomain) {
5
5
  if (region === undefined && subdomain === undefined)
6
6
  return undefined;
@@ -17,7 +17,7 @@ export function buildRoutingOptions(region, subdomain) {
17
17
  }
18
18
  if (region === "global")
19
19
  return { profile: "global" };
20
- if (!KNOWN_REGIONS.includes(region)) {
20
+ if (region === undefined || !KNOWN_REGIONS.includes(region)) {
21
21
  throw new Error(`Unrecognized Clockify region ${JSON.stringify(region)}. Provide one of ${KNOWN_REGIONS.join(", ")}.`);
22
22
  }
23
23
  return {
@@ -25,12 +25,21 @@ export function buildRoutingOptions(region, subdomain) {
25
25
  acknowledgeUnconfirmedRegion: true,
26
26
  };
27
27
  }
28
+ export function unconfirmedRegionNotice(routing) {
29
+ if (routing === undefined || routing.profile === "global")
30
+ return undefined;
31
+ const host = routing.profile === "subdomain" ? `${routing.subdomain} (${routing.region})` : routing.profile;
32
+ return `clk115: using the unconfirmed "${host}" Clockify profile. Only the global profile is live-confirmed; drop --region/--subdomain (and CLOCKIFY_REGION/CLOCKIFY_SUBDOMAIN or the rc-file entry) to route to api.clockify.me.`;
33
+ }
28
34
  export async function buildClient(config) {
29
35
  const apiKey = requireApiKey(config);
30
36
  const routing = buildRoutingOptions(config.region, config.subdomain);
31
37
  if (routing !== undefined && config.baseUrl !== undefined) {
32
38
  throw new Error("clk115: --region/--subdomain and --base-url configure the same thing two different ways; provide only one of them.");
33
39
  }
40
+ const notice = unconfirmedRegionNotice(routing);
41
+ if (notice !== undefined)
42
+ process.stderr.write(`${notice}\n`);
34
43
  const { createClockifyClient } = await import("clockify-sdk-ts-115");
35
44
  if (routing !== undefined) {
36
45
  return createClockifyClient({ apiKey, allowNonClockifyHttpsHost: false, routing });
@@ -175,15 +175,12 @@ function sourceFor(field, config, flags, env) {
175
175
  return "rc";
176
176
  return undefined;
177
177
  }
178
- if (field === "subdomain") {
179
- if (isPresent(flags.subdomain))
180
- return "flag";
181
- if (isPresent(env.CLOCKIFY_SUBDOMAIN))
182
- return "env";
183
- if (isPresent(config.subdomain))
184
- return "rc";
185
- return undefined;
186
- }
178
+ if (isPresent(flags.subdomain))
179
+ return "flag";
180
+ if (isPresent(env.CLOCKIFY_SUBDOMAIN))
181
+ return "env";
182
+ if (isPresent(config.subdomain))
183
+ return "rc";
187
184
  return undefined;
188
185
  }
189
186
  function isPresent(value) {
@@ -41,7 +41,7 @@ export const registerExpensesCommand = (program, services) => {
41
41
  const rows = result.items.map((raw) => {
42
42
  const e = raw;
43
43
  const category = typeof e.category === "object" && e.category !== null
44
- ? (e.category.name ?? "")
44
+ ? e.category.name ?? ""
45
45
  : typeof e.category === "string"
46
46
  ? e.category
47
47
  : "";
@@ -1,22 +1,29 @@
1
1
  import { InvalidArgumentError } from "commander";
2
2
  import { requireWorkspaceId } from "../config.js";
3
3
  import { globalFlags, resolveFlags } from "../index.js";
4
+ function parseStrictNumber(value) {
5
+ const trimmed = value.trim();
6
+ if (trimmed === "" || /^[+-]?0[xXoObB]/.test(trimmed)) {
7
+ return Number.NaN;
8
+ }
9
+ return Number(trimmed);
10
+ }
4
11
  export function parseIntArg(value) {
5
- const parsed = Number.parseInt(value, 10);
12
+ const parsed = parseStrictNumber(value);
6
13
  if (!Number.isInteger(parsed) || parsed <= 0) {
7
14
  throw new InvalidArgumentError("must be a positive integer.");
8
15
  }
9
16
  return parsed;
10
17
  }
11
18
  export function parseFloatArg(value) {
12
- const parsed = Number.parseFloat(value);
19
+ const parsed = parseStrictNumber(value);
13
20
  if (!Number.isFinite(parsed) || parsed <= 0) {
14
21
  throw new InvalidArgumentError("must be a positive number.");
15
22
  }
16
23
  return parsed;
17
24
  }
18
25
  export function parseSignedFloatArg(value) {
19
- const parsed = Number.parseFloat(value);
26
+ const parsed = parseStrictNumber(value);
20
27
  if (!Number.isFinite(parsed)) {
21
28
  throw new InvalidArgumentError("must be a number.");
22
29
  }
@@ -26,7 +33,7 @@ export function clampPageSize(value, max) {
26
33
  return Math.min(value, max);
27
34
  }
28
35
  export function splitList(value) {
29
- return String(value)
36
+ return value
30
37
  .split(",")
31
38
  .map((s) => s.trim())
32
39
  .filter((s) => s.length > 0);
@@ -4,8 +4,8 @@ function asNamed(rows) {
4
4
  return rows.map((r) => {
5
5
  const row = r;
6
6
  return {
7
- id: String(row.id ?? ""),
8
- name: String(row.name ?? ""),
7
+ id: row.id ?? "",
8
+ name: row.name ?? "",
9
9
  ...(row.archived !== undefined ? { archived: row.archived } : {}),
10
10
  };
11
11
  });
@@ -72,7 +72,7 @@ export const registerSchedulingCommand = (program, services) => {
72
72
  body.includeNonWorkingDays = true;
73
73
  const req = { workspaceId, body };
74
74
  const createdList = (await client.scheduling.createRecurring(req));
75
- const created = createdList?.[0] ?? {};
75
+ const created = createdList[0] ?? {};
76
76
  if (opts.publish === true) {
77
77
  await client.scheduling.publish({
78
78
  workspaceId,
@@ -71,8 +71,8 @@ const sharedUsersFilterSchema = z
71
71
  .strict();
72
72
  const sharedAttendanceFilterSchema = z
73
73
  .object({
74
- page: z.number().finite().int(INT_MESSAGE).optional(),
75
- pageSize: z.number().finite().int(INT_MESSAGE).optional(),
74
+ page: z.number().int(INT_MESSAGE).optional(),
75
+ pageSize: z.number().int(INT_MESSAGE).optional(),
76
76
  users: sharedUsersFilterSchema.optional(),
77
77
  })
78
78
  .strict();
@@ -80,8 +80,8 @@ const sharedDetailedFilterSchema = z
80
80
  .object({
81
81
  auditFilter: openObjectSchema.optional(),
82
82
  options: openObjectSchema.optional(),
83
- page: z.number().finite().int(INT_MESSAGE).optional(),
84
- pageSize: z.number().finite().int(INT_MESSAGE).optional(),
83
+ page: z.number().int(INT_MESSAGE).optional(),
84
+ pageSize: z.number().int(INT_MESSAGE).optional(),
85
85
  sortColumn: nonEmptyStringSchema.optional(),
86
86
  sortOrder: z.enum(["ASCENDING", "DESCENDING"]).optional(),
87
87
  })
@@ -215,7 +215,7 @@ function schemaIssueLabel(issue, operation) {
215
215
  return operation;
216
216
  }
217
217
  function sharedReportValidationError(error, operation, rawType) {
218
- const invalidTypeIssue = error.issues.find((issue) => issue.path[0] === "type" && issue.code === z.ZodIssueCode.invalid_value);
218
+ const invalidTypeIssue = error.issues.find((issue) => issue.path[0] === "type" && issue.code === "invalid_value");
219
219
  if (invalidTypeIssue !== undefined) {
220
220
  return new Error(`Unknown --type "${String(rawType)}". Provide one of: ${SHARED_REPORT_TYPES.join(", ")}.`);
221
221
  }
@@ -224,12 +224,12 @@ function sharedReportValidationError(error, operation, rawType) {
224
224
  return new Error(`${operation}: invalid request.`);
225
225
  if (issue.path.length === 1 &&
226
226
  issue.path[0] === "filter" &&
227
- issue.code === z.ZodIssueCode.invalid_type &&
227
+ issue.code === "invalid_type" &&
228
228
  issue.expected === "object") {
229
229
  return new Error("--filter must be a JSON object.");
230
230
  }
231
231
  const label = schemaIssueLabel(issue, operation);
232
- if (issue.code === z.ZodIssueCode.unrecognized_keys) {
232
+ if (issue.code === "unrecognized_keys") {
233
233
  const fieldKind = issue.path[0] === "filter" ? "filter field(s)" : "field(s)";
234
234
  return new Error(`${label} has unknown ${fieldKind}: ${issue.keys.join(", ")}.`);
235
235
  }
@@ -40,7 +40,7 @@ export const registerTimeOffCommand = (program, services) => {
40
40
  const rows = items.map((raw) => {
41
41
  const r = raw;
42
42
  const statusValue = typeof r.status === "object" && r.status !== null
43
- ? (r.status.statusType ?? "")
43
+ ? r.status.statusType ?? ""
44
44
  : typeof r.status === "string"
45
45
  ? r.status
46
46
  : "";
@@ -245,6 +245,9 @@ export function errorCodeForMessage(message) {
245
245
  return "not_found";
246
246
  if (/(unauthorized|forbidden|permission|api[\s_-]?key|addon[\s_-]?token|CLOCKIFY_API_KEY|CLOCKIFY_ADDON_TOKEN|workspace id not set)/i.test(message))
247
247
  return "auth_or_permission";
248
+ if (/(upstream|gateway|bad gateway|service unavailable|internal server error)/i.test(message)) {
249
+ return "clockify_upstream_error";
250
+ }
248
251
  if (/(required|provide|missing|invalid|unknown option|unknown command|could not parse|not valid|must use|must not|confirmation token)/i.test(message)) {
249
252
  return "invalid_request";
250
253
  }
@@ -1 +1 @@
1
- export const PACKAGE_VERSION = "0.6.1";
1
+ export const PACKAGE_VERSION = "2.0.0";
package/dist/index.js CHANGED
@@ -78,12 +78,15 @@ export function buildProgram(services = defaultServices) {
78
78
  });
79
79
  return program;
80
80
  }
81
+ function isTty(stream) {
82
+ return stream.isTTY === true;
83
+ }
81
84
  export function resolveFlags(program) {
82
85
  const opts = program.opts();
83
86
  const mode = resolveMode(opts.output, opts.json);
84
87
  const resolved = {
85
88
  mode,
86
- color: opts.color !== false && process.stdout.isTTY === true,
89
+ color: opts.color !== false && isTty(process.stdout),
87
90
  };
88
91
  if (opts.compact)
89
92
  resolved.compact = true;
@@ -99,7 +102,7 @@ function resolveFlagsSafe(program) {
99
102
  const opts = program.opts();
100
103
  return {
101
104
  mode: "table",
102
- color: opts.color !== false && process.stdout.isTTY === true,
105
+ color: opts.color !== false && isTty(process.stdout),
103
106
  };
104
107
  }
105
108
  }
@@ -149,7 +152,7 @@ export async function main(argv, services = defaultServices) {
149
152
  }
150
153
  catch (err) {
151
154
  if (isCommanderHelpError(err)) {
152
- return Number(err.exitCode ?? 0);
155
+ return err.exitCode ?? 0;
153
156
  }
154
157
  const message = err instanceof Error ? err.message : String(err);
155
158
  const statusCode = err.statusCode;
package/dist/output.js CHANGED
@@ -42,18 +42,6 @@ export function printObject(obj, opts) {
42
42
  }
43
43
  console.log(table.toString());
44
44
  }
45
- export function printSuccess(message, opts) {
46
- if (opts.mode === "ndjson") {
47
- printNdjson({ ok: true, message }, opts);
48
- return;
49
- }
50
- if (opts.mode === "json") {
51
- printJson({ ok: true, message }, opts);
52
- return;
53
- }
54
- const prefix = opts.color ? pc.green("OK") : "OK";
55
- console.log(`${prefix} ${message}`);
56
- }
57
45
  export function printError(message, opts, statusCode) {
58
46
  const messageCode = errorCodeForMessage(message);
59
47
  const code = messageCode === "not_found" && statusCode === 400
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apet97/clockify-cli-115",
3
- "version": "0.6.1",
3
+ "version": "2.0.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>",
@@ -54,7 +54,7 @@
54
54
  "zod": "^4.4.3"
55
55
  },
56
56
  "peerDependencies": {
57
- "clockify-sdk-ts-115": ">=0.15.1 <1"
57
+ "clockify-sdk-ts-115": "^2"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/node": "^22",
@@ -63,7 +63,7 @@
63
63
  "eslint": "^10.8.0",
64
64
  "eslint-plugin-import-x": "^4.17.1",
65
65
  "tsx": "^4.23.1",
66
- "typescript": "^5.7.0",
66
+ "typescript": "^7.0.2",
67
67
  "typescript-eslint": "^8.65.0",
68
68
  "vitest": "^4.1.10"
69
69
  },