@apet97/clockify-cli-115 5.0.4 → 6.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.
Files changed (40) hide show
  1. package/README.md +96 -26
  2. package/dist/client.js +18 -15
  3. package/dist/closed-pipe.js +3 -0
  4. package/dist/commands/api.js +182 -61
  5. package/dist/commands/approvals.js +9 -7
  6. package/dist/commands/auditlog.js +11 -8
  7. package/dist/commands/balanceAssignment.js +10 -8
  8. package/dist/commands/clients.js +16 -7
  9. package/dist/commands/doctor.js +42 -25
  10. package/dist/commands/entries.js +29 -14
  11. package/dist/commands/expenses.js +64 -22
  12. package/dist/commands/helpers.js +28 -7
  13. package/dist/commands/invoices.js +12 -16
  14. package/dist/commands/leaf-command.js +8 -0
  15. package/dist/commands/log.js +4 -2
  16. package/dist/commands/projects.js +18 -9
  17. package/dist/commands/reports.js +32 -14
  18. package/dist/commands/resolve-refs.js +30 -53
  19. package/dist/commands/scheduling.js +94 -40
  20. package/dist/commands/shared-report-body.js +205 -0
  21. package/dist/commands/sharedReports.js +19 -215
  22. package/dist/commands/start.js +6 -4
  23. package/dist/commands/status.js +55 -19
  24. package/dist/commands/stop.js +15 -17
  25. package/dist/commands/tags.js +6 -4
  26. package/dist/commands/tasks.js +18 -23
  27. package/dist/commands/timeoff.js +23 -16
  28. package/dist/commands/users.js +7 -5
  29. package/dist/commands/webhooks.js +14 -12
  30. package/dist/completions.js +290 -55
  31. package/dist/config.js +10 -6
  32. package/dist/duration.js +5 -4
  33. package/dist/error-codes.js +34 -6
  34. package/dist/failure.js +87 -0
  35. package/dist/flags.js +74 -0
  36. package/dist/generated/version.js +1 -1
  37. package/dist/index.js +41 -105
  38. package/dist/output.js +62 -28
  39. package/dist/write-outcome.js +84 -0
  40. package/package.json +3 -3
@@ -1,6 +1,8 @@
1
+ import { entityId } from "clockify-sdk-ts-115/operation-receipt";
1
2
  import { InvalidArgumentError } from "commander";
2
3
  import { requireWorkspaceId } from "../config.js";
3
- import { globalFlags, resolveFlags } from "../index.js";
4
+ import { UsageError } from "../failure.js";
5
+ import { globalFlags, resolveFlags } from "../flags.js";
4
6
  function parseStrictNumber(value) {
5
7
  const trimmed = value.trim();
6
8
  if (trimmed === "" || /^[+-]?0[xXoObB]/.test(trimmed)) {
@@ -8,6 +10,18 @@ function parseStrictNumber(value) {
8
10
  }
9
11
  return Number(trimmed);
10
12
  }
13
+ export const TIME_VIEW_MODES = [
14
+ "TIME_SENSITIVE_VIEW",
15
+ "AGGREGATED_TIME_VIEW",
16
+ ];
17
+ export const TIME_VIEW_MODE_HELP = "Time view mode: TIME_SENSITIVE_VIEW (server default) or AGGREGATED_TIME_VIEW (needs Original time view enabled on the workspace).";
18
+ export function parseTimeViewMode(value) {
19
+ const mode = String(value).toUpperCase();
20
+ if (!TIME_VIEW_MODES.includes(mode)) {
21
+ throw new UsageError(`Unknown --time-view-mode "${String(value)}". Provide one of: ${TIME_VIEW_MODES.join(", ")}.`);
22
+ }
23
+ return mode;
24
+ }
11
25
  export function parseIntArg(value) {
12
26
  const parsed = parseStrictNumber(value);
13
27
  if (!Number.isInteger(parsed) || parsed <= 0) {
@@ -71,13 +85,13 @@ function isRfc3339Timestamp(value) {
71
85
  export function requireCalendarDate(value, flag) {
72
86
  const match = BARE_DATE_PATTERN.exec(value);
73
87
  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`);
88
+ throw new UsageError(`--${flag} ${JSON.stringify(value)} is not a valid calendar date (YYYY-MM-DD); provide a real calendar date`);
75
89
  }
76
90
  return value;
77
91
  }
78
92
  export function requireRfc3339Timestamp(value, flag) {
79
93
  if (!isRfc3339Timestamp(value)) {
80
- throw new Error(`--${flag} ${JSON.stringify(value)} is not a valid RFC3339 timestamp; provide a value such as 2026-06-22T09:30:00Z`);
94
+ throw new UsageError(`--${flag} ${JSON.stringify(value)} is not a valid RFC3339 timestamp; provide a value such as 2026-06-22T09:30:00Z`);
81
95
  }
82
96
  return value;
83
97
  }
@@ -86,7 +100,7 @@ export function requireDateOrRfc3339(value, flag) {
86
100
  return requireCalendarDate(value, flag);
87
101
  }
88
102
  if (!isRfc3339Timestamp(value)) {
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`);
103
+ throw new UsageError(`--${flag} ${JSON.stringify(value)} is not a valid date (YYYY-MM-DD) or RFC3339 timestamp; provide YYYY-MM-DD or an RFC3339 timestamp`);
90
104
  }
91
105
  return value;
92
106
  }
@@ -104,14 +118,21 @@ export function rootProgram(cmd) {
104
118
  }
105
119
  return current;
106
120
  }
107
- export async function resolveBaseContext(cmd, services) {
121
+ export async function resolveBaseContext(cmd, services, resolvedOutput) {
108
122
  const program = rootProgram(cmd);
123
+ const output = resolvedOutput ?? resolveFlags(program);
109
124
  const config = services.loadConfig(globalFlags(program));
110
- const client = await services.buildClient(config);
111
- const output = resolveFlags(program);
125
+ const client = await services.buildClient(config, cmd);
112
126
  return { client, config, output };
113
127
  }
114
128
  export async function resolveContext(cmd, services) {
115
129
  const { client, config, output } = await resolveBaseContext(cmd, services);
116
130
  return { client, workspaceId: requireWorkspaceId(config), output };
117
131
  }
132
+ export async function requireCurrentUserId(client, hint) {
133
+ const userId = entityId(await client.users.getCurrentUser());
134
+ if (!userId) {
135
+ throw new Error(`could not determine user ID from the current-user response${hint ? `; ${hint}` : ""}`);
136
+ }
137
+ return userId;
138
+ }
@@ -1,11 +1,8 @@
1
1
  import { printRecords } from "../output.js";
2
2
  import { printReceipt } from "../receipt.js";
3
- import { clampPageSize, parseIntArg, promoteDateBoundary, resolveContext } from "./helpers.js";
3
+ import { dispatchedWrite } from "../write-outcome.js";
4
+ import { clampPageSize, parseIntArg, parseTimeViewMode, promoteDateBoundary, resolveContext, TIME_VIEW_MODE_HELP, } from "./helpers.js";
4
5
  import { leafCommand } from "./leaf-command.js";
5
- const TIME_VIEW_MODES = [
6
- "TIME_SENSITIVE_VIEW",
7
- "AGGREGATED_TIME_VIEW",
8
- ];
9
6
  export const registerInvoicesCommand = (program, services) => {
10
7
  const invoices = program.command("invoices").description("Manage invoices.");
11
8
  leafCommand(invoices, "list", "read")
@@ -28,7 +25,11 @@ export const registerInvoicesCommand = (program, services) => {
28
25
  number: inv.number ?? "",
29
26
  client: inv.clientName ?? inv.clientId ?? "",
30
27
  currency: inv.currency ?? "",
31
- amount: inv.amount ?? 0,
28
+ ...(output.mode === "table" ? { amount: inv.amount ?? "—" } : {
29
+ amount: inv.amount ?? 0,
30
+ totalMinor: inv.amount ?? null,
31
+ amountSource: inv.amount == null ? "unavailable" : "total",
32
+ }),
32
33
  status: inv.status ?? "",
33
34
  issued: inv.issuedDate ?? "",
34
35
  due: inv.dueDate ?? "",
@@ -46,9 +47,8 @@ export const registerInvoicesCommand = (program, services) => {
46
47
  .requiredOption("--currency <code>", "ISO currency code (e.g. USD, EUR).")
47
48
  .requiredOption("--issued <date>", "Issued date (YYYY-MM-DD or RFC3339).")
48
49
  .requiredOption("--due <date>", "Due date (YYYY-MM-DD or RFC3339).")
49
- .option("--time-view-mode <mode>", "Time view mode: TIME_SENSITIVE_VIEW or AGGREGATED_TIME_VIEW.")
50
+ .option("--time-view-mode <mode>", TIME_VIEW_MODE_HELP)
50
51
  .action(async function (opts) {
51
- const { client, workspaceId, output } = await resolveContext(this, services);
52
52
  const body = {
53
53
  clientId: opts.client,
54
54
  number: opts.number,
@@ -56,15 +56,11 @@ export const registerInvoicesCommand = (program, services) => {
56
56
  issuedDate: normaliseInvoiceDate(opts.issued, "issued"),
57
57
  dueDate: normaliseInvoiceDate(opts.due, "due"),
58
58
  };
59
- if (opts.timeViewMode !== undefined) {
60
- const mode = String(opts.timeViewMode).toUpperCase();
61
- if (!TIME_VIEW_MODES.includes(mode)) {
62
- throw new Error(`Unknown --time-view-mode "${String(opts.timeViewMode)}". Provide one of: ${TIME_VIEW_MODES.join(", ")}.`);
63
- }
64
- body.timeViewMode = mode;
65
- }
59
+ if (opts.timeViewMode !== undefined)
60
+ body.timeViewMode = parseTimeViewMode(opts.timeViewMode);
61
+ const { client, workspaceId, output } = await resolveContext(this, services);
66
62
  const req = { workspaceId, body };
67
- const created = (await client.invoices.create(req));
63
+ const created = (await dispatchedWrite(this, client.invoices.create(req)));
68
64
  const data = {
69
65
  id: created.id ?? "",
70
66
  number: created.number ?? "",
@@ -1,4 +1,12 @@
1
1
  const commandRisks = new WeakMap();
2
+ export function isMutationCommand(command) {
3
+ if (command.name() === "api") {
4
+ const method = command.args[0]?.toUpperCase();
5
+ return method !== undefined && ["POST", "PUT", "PATCH", "DELETE"].includes(method);
6
+ }
7
+ const risk = commandRisks.get(command);
8
+ return risk === "write" || risk === "destructive";
9
+ }
2
10
  export function leafCommand(parent, syntax, risk) {
3
11
  if (commandRisks.has(parent)) {
4
12
  throw new Error(`A classified leaf cannot become a grouping node: ${parent.name()}`);
@@ -1,5 +1,7 @@
1
1
  import { parseDuration } from "../duration.js";
2
+ import { UsageError } from "../failure.js";
2
3
  import { printReceipt } from "../receipt.js";
4
+ import { dispatchedWrite } from "../write-outcome.js";
3
5
  import { requireRfc3339Timestamp, resolveContext } from "./helpers.js";
4
6
  import { leafCommand } from "./leaf-command.js";
5
7
  import { resolveProjectId, resolveTaskId, resolveTagIds } from "./resolve-refs.js";
@@ -18,7 +20,7 @@ export const registerLogCommand = (program, services) => {
18
20
  .option("--end <iso>", "End timestamp (ISO 8601). Defaults to now.")
19
21
  .action(async function (duration, description, opts) {
20
22
  if (opts.task && !opts.project) {
21
- throw new Error("--task requires --project: a task entry must be scoped to its project.");
23
+ throw new UsageError("--task requires --project: a task entry must be scoped to its project.");
22
24
  }
23
25
  const seconds = parseDuration(duration);
24
26
  const endInput = requireRfc3339Timestamp(opts.end ?? new Date().toISOString(), "end");
@@ -49,7 +51,7 @@ export const registerLogCommand = (program, services) => {
49
51
  if (opts.billable)
50
52
  body.billable = true;
51
53
  const req = { workspaceId, body };
52
- const created = await client.timeEntries.create(req);
54
+ const created = await dispatchedWrite(this, client.timeEntries.create(req));
53
55
  const entry = created;
54
56
  const data = {
55
57
  id: entry.id ?? "",
@@ -1,6 +1,8 @@
1
1
  import { archiveThenDeleteProject } from "clockify-sdk-ts-115/ensure";
2
+ import { PartialDeleteError, UsageError } from "../failure.js";
2
3
  import { printObject, printRecords } from "../output.js";
3
4
  import { printReceipt } from "../receipt.js";
5
+ import { dispatchedWrite } from "../write-outcome.js";
4
6
  import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
5
7
  import { leafCommand } from "./leaf-command.js";
6
8
  function projectUpdateCarryFields(current) {
@@ -68,7 +70,7 @@ export const registerProjectsCommand = (program, services) => {
68
70
  ...(opts.billable ? { billable: true } : {}),
69
71
  },
70
72
  };
71
- const created = (await client.projects.create(req));
73
+ const created = (await dispatchedWrite(this, client.projects.create(req)));
72
74
  const data = {
73
75
  id: created.id ?? "",
74
76
  name: created.name ?? "",
@@ -121,7 +123,7 @@ export const registerProjectsCommand = (program, services) => {
121
123
  opts.billable !== undefined ||
122
124
  opts.archived !== undefined;
123
125
  if (!hasChanges) {
124
- throw new Error("projects.update needs a change: provide at least one project field.");
126
+ throw new UsageError("projects.update needs a change: provide at least one project field.");
125
127
  }
126
128
  const { client, workspaceId, output } = await resolveContext(this, services);
127
129
  const current = await client.projects.get({ workspaceId, projectId: id });
@@ -139,7 +141,7 @@ export const registerProjectsCommand = (program, services) => {
139
141
  if (opts.archived !== undefined)
140
142
  body.archived = opts.archived;
141
143
  const req = { workspaceId, projectId: id, body };
142
- const updated = (await client.projects.update(req));
144
+ const updated = (await dispatchedWrite(this, client.projects.update(req)));
143
145
  const data = { id: updated.id ?? id, name: updated.name ?? "" };
144
146
  printReceipt({
145
147
  ok: true,
@@ -162,6 +164,7 @@ export const registerProjectsCommand = (program, services) => {
162
164
  .addHelpText("after", "\nExamples:\n" + " $ clk115 projects delete project_123\n")
163
165
  .action(async function (id) {
164
166
  const { client, workspaceId, output } = await resolveContext(this, services);
167
+ let archivedByCall = false;
165
168
  await archiveThenDeleteProject({
166
169
  workspaceId,
167
170
  id,
@@ -169,19 +172,25 @@ export const registerProjectsCommand = (program, services) => {
169
172
  getCurrent: ({ workspaceId: currentWorkspaceId, id: projectId }) => client.projects.get({ workspaceId: currentWorkspaceId, projectId }),
170
173
  archive: async ({ workspaceId: currentWorkspaceId, id: projectId, current, }) => {
171
174
  const preserved = projectUpdateCarryFields(current);
172
- await client.projects.update({
175
+ await dispatchedWrite(this, client.projects.update({
173
176
  workspaceId: currentWorkspaceId,
174
177
  projectId,
175
178
  name: current.name,
176
179
  ...preserved,
177
180
  archived: true,
178
- });
181
+ }));
182
+ archivedByCall = true;
179
183
  },
180
184
  delete: async ({ workspaceId: currentWorkspaceId, id: projectId }) => {
181
- await client.projects.delete({
182
- workspaceId: currentWorkspaceId,
183
- projectId,
184
- });
185
+ try {
186
+ await dispatchedWrite(this, client.projects.delete({
187
+ workspaceId: currentWorkspaceId,
188
+ projectId,
189
+ }));
190
+ }
191
+ catch (cause) {
192
+ throw new PartialDeleteError(cause, "archived", `clk115 projects get ${id} --json`, archivedByCall ? "archived_by_call" : "already_archived");
193
+ }
185
194
  },
186
195
  },
187
196
  });
@@ -1,7 +1,8 @@
1
1
  import { REPORT_PERIODS, isExactWeeklyRange, parseWeeklyDateTime, resolveInstant, resolvePeriod, } from "clockify-sdk-ts-115/dates";
2
2
  import { detailedFilter, summaryFilter, weeklyFilter } from "clockify-sdk-ts-115/reports";
3
+ import { UsageError } from "../failure.js";
3
4
  import { printObject } from "../output.js";
4
- import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
5
+ import { clampPageSize, parseIntArg, parseTimeViewMode, resolveContext, TIME_VIEW_MODE_HELP } from "./helpers.js";
5
6
  import { leafCommand } from "./leaf-command.js";
6
7
  import { resolveClientId, resolveProjectId } from "./resolve-refs.js";
7
8
  function resolveRange(opts) {
@@ -11,20 +12,20 @@ function resolveRange(opts) {
11
12
  .toLowerCase()
12
13
  .replace(/[\s-]+/g, "_");
13
14
  if (!REPORT_PERIODS.includes(periodInput)) {
14
- throw new Error(`Unknown --period "${opts.period}". Provide one of: ${REPORT_PERIODS.join(", ")}.`);
15
+ throw new UsageError(`Unknown --period "${opts.period}". Provide one of: ${REPORT_PERIODS.join(", ")}.`);
15
16
  }
16
17
  const range = resolvePeriod(now, periodInput);
17
18
  let { dateRangeStart, dateRangeEnd } = range;
18
19
  if (opts.from) {
19
20
  const start = resolveInstant(now, opts.from, "start");
20
21
  if (!start)
21
- throw new Error(`--from "${opts.from}" is not a valid date, ISO timestamp, or period; provide YYYY-MM-DD, an ISO timestamp, or a period name.`);
22
+ throw new UsageError(`--from "${opts.from}" is not a valid date, ISO timestamp, or period; provide YYYY-MM-DD, an ISO timestamp, or a period name.`);
22
23
  dateRangeStart = start;
23
24
  }
24
25
  if (opts.to) {
25
26
  const end = resolveInstant(now, opts.to, "end");
26
27
  if (!end)
27
- throw new Error(`--to "${opts.to}" is not a valid date, ISO timestamp, or period; provide YYYY-MM-DD, an ISO timestamp, or a period name.`);
28
+ throw new UsageError(`--to "${opts.to}" is not a valid date, ISO timestamp, or period; provide YYYY-MM-DD, an ISO timestamp, or a period name.`);
28
29
  dateRangeEnd = end;
29
30
  }
30
31
  return { dateRangeStart, dateRangeEnd };
@@ -45,7 +46,7 @@ function resolveWeeklyRange(opts) {
45
46
  dateRangeEnd = isExactWeeklyRange(dateRangeStart, exclusive) ? exclusive : inclusive;
46
47
  }
47
48
  if (!isExactWeeklyRange(dateRangeStart, dateRangeEnd)) {
48
- throw new Error("Weekly reports require one exact seven-day interval (exclusive next-midnight end or inclusive final-day 23:59:59 end). Provide --from and --to for one Monday-Sunday window or use --period last_week.");
49
+ throw new UsageError("Weekly reports require one exact seven-day interval (exclusive next-midnight end or inclusive final-day 23:59:59 end). Provide --from and --to for one Monday-Sunday window or use --period last_week.");
49
50
  }
50
51
  return { dateRangeStart, dateRangeEnd };
51
52
  }
@@ -54,7 +55,7 @@ function inspectWeeklyInput(raw, option) {
54
55
  return undefined;
55
56
  const trimmed = raw.trim();
56
57
  if (trimmed.length === 0) {
57
- throw new Error(`${option} must not be empty; provide YYYY-MM-DD, a full-seconds weekly timestamp, or a period name.`);
58
+ throw new UsageError(`${option} must not be empty; provide YYYY-MM-DD, a full-seconds weekly timestamp, or a period name.`);
58
59
  }
59
60
  if (isDateOnly(trimmed)) {
60
61
  if (parseWeeklyDateTime(`${trimmed}T00:00:00`) === undefined) {
@@ -73,7 +74,7 @@ function isDateOnly(value) {
73
74
  return /^\d{4}-\d{2}-\d{2}$/u.test(value);
74
75
  }
75
76
  function invalidWeeklyInput(option, raw) {
76
- return new Error(`${option} "${raw}" is not a valid date, full-seconds weekly timestamp, or period; use YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS[.fffffffff][Z].`);
77
+ return new UsageError(`${option} "${raw}" is not a valid date, full-seconds weekly timestamp, or period; use YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS[.fffffffff][Z].`);
77
78
  }
78
79
  function idFilter(ids) {
79
80
  return { ids, contains: "CONTAINS" };
@@ -95,29 +96,32 @@ function parseSummaryGroups(raw) {
95
96
  .map((group) => group.trim().toUpperCase())
96
97
  .filter(Boolean);
97
98
  if (groups.length === 0 || groups.length > 3) {
98
- throw new Error(`--groups must contain between one and three summary groups; provide 1-3 of: ${SUMMARY_GROUPS.join(", ")}.`);
99
+ throw new UsageError(`--groups must contain between one and three summary groups; provide 1-3 of: ${SUMMARY_GROUPS.join(", ")}.`);
99
100
  }
100
101
  const unknown = groups.find((group) => !SUMMARY_GROUPS.includes(group));
101
102
  if (unknown) {
102
- throw new Error(`Unknown summary group: ${unknown}. Provide one of: ${SUMMARY_GROUPS.join(", ")}.`);
103
+ throw new UsageError(`Unknown summary group: ${unknown}. Provide one of: ${SUMMARY_GROUPS.join(", ")}.`);
103
104
  }
104
105
  return groups;
105
106
  }
106
107
  function parseWeeklyGroup(raw) {
107
108
  const group = String(raw).toUpperCase();
108
109
  if (group !== "USER" && group !== "PROJECT") {
109
- throw new Error("Unknown --group for the weekly report. Provide one of: USER, PROJECT.");
110
+ throw new UsageError("Unknown --group for the weekly report. Provide one of: USER, PROJECT.");
110
111
  }
111
112
  return group;
112
113
  }
113
114
  function parseWeeklySubgroup(raw) {
114
115
  const subgroup = String(raw).toUpperCase();
115
116
  if (subgroup !== "TIME") {
116
- throw new Error("Unknown --subgroup for the weekly report. Provide one of: TIME.");
117
+ throw new UsageError("Unknown --subgroup for the weekly report. Provide one of: TIME.");
117
118
  }
118
119
  return subgroup;
119
120
  }
120
121
  const PERIOD_HELP = `Named period: ${REPORT_PERIODS.join(", ")} (default this_month).`;
122
+ function optionalTimeViewMode(opts) {
123
+ return opts.timeViewMode === undefined ? undefined : parseTimeViewMode(opts.timeViewMode);
124
+ }
121
125
  export const registerReportsCommand = (program, services) => {
122
126
  const reports = program.command("reports").description("Run Clockify reports (read-only).");
123
127
  leafCommand(reports, "summary", "read")
@@ -132,16 +136,20 @@ export const registerReportsCommand = (program, services) => {
132
136
  .option("--billable", "Only billable time.", false)
133
137
  .option("--project <name|id...>", "Scope to one or more project names or ids.")
134
138
  .option("--client <name|id...>", "Scope to one or more client names or ids.")
139
+ .option("--time-view-mode <mode>", TIME_VIEW_MODE_HELP)
135
140
  .action(async function (opts) {
136
- const { client, workspaceId, output } = await resolveContext(this, services);
137
141
  const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
138
142
  const groups = parseSummaryGroups(opts.groups);
143
+ const timeViewMode = optionalTimeViewMode(opts);
144
+ const { client, workspaceId, output } = await resolveContext(this, services);
139
145
  const req = {
140
146
  workspaceId,
141
147
  dateRangeStart,
142
148
  dateRangeEnd,
143
149
  summaryFilter: summaryFilter(groups),
144
150
  };
151
+ if (timeViewMode !== undefined)
152
+ req.timeViewMode = timeViewMode;
145
153
  if (opts.billable)
146
154
  req.billable = true;
147
155
  if (Array.isArray(opts.project) && opts.project.length > 0) {
@@ -163,7 +171,9 @@ export const registerReportsCommand = (program, services) => {
163
171
  .option("--to <date>", "Range end; overrides --period.")
164
172
  .option("--page <n>", "Page number.", parseIntArg, 1)
165
173
  .option("--page-size <n>", "Entries per page (max 1000).", parseIntArg, 50)
174
+ .option("--time-view-mode <mode>", TIME_VIEW_MODE_HELP)
166
175
  .action(async function (opts) {
176
+ const timeViewMode = optionalTimeViewMode(opts);
167
177
  const { client, workspaceId, output } = await resolveContext(this, services);
168
178
  const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
169
179
  const req = {
@@ -174,6 +184,7 @@ export const registerReportsCommand = (program, services) => {
174
184
  page: opts.page,
175
185
  pageSize: clampPageSize(opts.pageSize, 1000),
176
186
  }),
187
+ ...(timeViewMode !== undefined ? { timeViewMode } : {}),
177
188
  };
178
189
  const data = await client.reports.detailed(req);
179
190
  printObject(data, output);
@@ -186,14 +197,18 @@ export const registerReportsCommand = (program, services) => {
186
197
  .option("--to <date>", "Range end; overrides --period.")
187
198
  .option("--group <group>", "Top grouping: USER or PROJECT.", "USER")
188
199
  .option("--subgroup <subgroup>", "Subgrouping (TIME).", "TIME")
200
+ .option("--time-view-mode <mode>", TIME_VIEW_MODE_HELP)
189
201
  .action(async function (opts) {
190
- const { client, workspaceId, output } = await resolveContext(this, services);
191
202
  const { dateRangeStart, dateRangeEnd } = resolveWeeklyRange(opts);
203
+ const timeViewMode = optionalTimeViewMode(opts);
204
+ const filter = weeklyFilter(parseWeeklyGroup(opts.group), parseWeeklySubgroup(opts.subgroup));
205
+ const { client, workspaceId, output } = await resolveContext(this, services);
192
206
  const req = {
193
207
  workspaceId,
194
208
  dateRangeStart,
195
209
  dateRangeEnd,
196
- weeklyFilter: weeklyFilter(parseWeeklyGroup(opts.group), parseWeeklySubgroup(opts.subgroup)),
210
+ weeklyFilter: filter,
211
+ ...(timeViewMode !== undefined ? { timeViewMode } : {}),
197
212
  };
198
213
  const data = await client.reports.weekly(req);
199
214
  printObject(data, output);
@@ -204,7 +219,9 @@ export const registerReportsCommand = (program, services) => {
204
219
  .option("--period <p>", PERIOD_HELP)
205
220
  .option("--from <date>", "Range start; overrides --period.")
206
221
  .option("--to <date>", "Range end; overrides --period.")
222
+ .option("--time-view-mode <mode>", TIME_VIEW_MODE_HELP)
207
223
  .action(async function (opts) {
224
+ const timeViewMode = optionalTimeViewMode(opts);
208
225
  const { client, workspaceId, output } = await resolveContext(this, services);
209
226
  const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
210
227
  const req = {
@@ -212,6 +229,7 @@ export const registerReportsCommand = (program, services) => {
212
229
  dateRangeStart,
213
230
  dateRangeEnd,
214
231
  attendanceFilter: {},
232
+ ...(timeViewMode !== undefined ? { timeViewMode } : {}),
215
233
  };
216
234
  const data = await client.reports.attendance(req);
217
235
  printObject(data, output);
@@ -1,66 +1,47 @@
1
1
  import { iterAll } from "clockify-sdk-ts-115/iter";
2
2
  import { looksLikeClockifyId, matchByName } from "clockify-sdk-ts-115/resolve";
3
- function asNamed(rows) {
4
- return rows.map((r) => {
5
- const row = r;
6
- return {
7
- id: row.id ?? "",
8
- name: row.name ?? "",
9
- ...(row.archived !== undefined ? { archived: row.archived } : {}),
10
- };
11
- });
12
- }
13
- function pickIdByName(rows, ref, noun) {
14
- const match = matchByName(asNamed(rows), ref);
15
- if (match.kind === "many") {
16
- throw new Error(`multiple ${noun}s named ${JSON.stringify(ref)}; provide the 24-character id instead`);
17
- }
18
- if (match.kind === "none") {
19
- throw new Error(`${noun} ${JSON.stringify(ref)} not found in workspace`);
20
- }
21
- return match.entity.id;
22
- }
23
- async function collectPaged(fetcher, baseRequest) {
24
- const rows = [];
25
- for await (const row of iterAll(fetcher, baseRequest, { pageSize: 200, maxPages: 1000 })) {
26
- rows.push(row);
3
+ import { LookupError } from "../failure.js";
4
+ async function resolveName(fetcher, baseRequest, ref, noun, projectId) {
5
+ const name = JSON.stringify(ref);
6
+ const scope = projectId === undefined ? "in workspace" : `on project ${projectId}`;
7
+ const options = {
8
+ pageSize: 200,
9
+ maxPages: 1000,
10
+ onTruncated: () => {
11
+ throw new LookupError("capped", `${noun} lookup for ${name} reached the page cap; provide the 24-character id instead`);
12
+ },
13
+ };
14
+ let id;
15
+ for await (const row of iterAll(fetcher, baseRequest, options)) {
16
+ if (!row.id || !row.name)
17
+ continue;
18
+ const candidate = { name: row.name, archived: row.archived === true };
19
+ if (matchByName([candidate], ref).kind === "none")
20
+ continue;
21
+ if (id !== undefined && row.id !== id) {
22
+ const location = projectId === undefined ? "" : ` ${scope}`;
23
+ throw new LookupError("ambiguous", `multiple ${noun}s named ${name}${location}; provide the 24-character id instead`);
24
+ }
25
+ id = row.id;
27
26
  }
28
- return rows;
27
+ if (id === undefined)
28
+ throw new LookupError("not_found", `${noun} ${name} not found ${scope}`);
29
+ return id;
29
30
  }
30
31
  export async function resolveProjectId(client, workspaceId, ref) {
31
32
  if (looksLikeClockifyId(ref))
32
33
  return ref;
33
- const list = await collectPaged(client.projects.list.bind(client.projects), {
34
- workspaceId,
35
- name: ref,
36
- });
37
- return pickIdByName(list, ref, "project");
34
+ return resolveName(client.projects.list.bind(client.projects), { workspaceId, name: ref }, ref, "project");
38
35
  }
39
36
  export async function resolveClientId(client, workspaceId, ref) {
40
37
  if (looksLikeClockifyId(ref))
41
38
  return ref;
42
- const list = await collectPaged(client.clients.list.bind(client.clients), {
43
- workspaceId,
44
- name: ref,
45
- });
46
- return pickIdByName(list, ref, "client");
39
+ return resolveName(client.clients.list.bind(client.clients), { workspaceId, name: ref }, ref, "client");
47
40
  }
48
41
  export async function resolveTaskId(client, workspaceId, projectId, ref) {
49
42
  if (looksLikeClockifyId(ref))
50
43
  return ref;
51
- const list = await collectPaged(client.tasks.list.bind(client.tasks), {
52
- workspaceId,
53
- projectId,
54
- name: ref,
55
- });
56
- const match = matchByName(asNamed(list), ref);
57
- if (match.kind === "many") {
58
- throw new Error(`multiple tasks named ${JSON.stringify(ref)} on project ${projectId}; provide the 24-character id`);
59
- }
60
- if (match.kind === "none") {
61
- throw new Error(`task ${JSON.stringify(ref)} not found on project ${projectId}`);
62
- }
63
- return match.entity.id;
44
+ return resolveName(client.tasks.list.bind(client.tasks), { workspaceId, projectId, name: ref }, ref, "task", projectId);
64
45
  }
65
46
  export async function resolveTagIds(client, workspaceId, refs) {
66
47
  const ids = [];
@@ -69,11 +50,7 @@ export async function resolveTagIds(client, workspaceId, refs) {
69
50
  ids.push(ref);
70
51
  continue;
71
52
  }
72
- const list = await collectPaged(client.tags.list.bind(client.tags), {
73
- workspaceId,
74
- name: ref,
75
- });
76
- ids.push(pickIdByName(list, ref, "tag"));
53
+ ids.push(await resolveName(client.tags.list.bind(client.tags), { workspaceId, name: ref }, ref, "tag"));
77
54
  }
78
55
  return ids;
79
56
  }