@apet97/clockify-cli-115 6.0.0 → 8.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 (48) hide show
  1. package/README.md +167 -21
  2. package/dist/client.js +30 -7
  3. package/dist/commands/api.js +44 -76
  4. package/dist/commands/approvals.js +2 -5
  5. package/dist/commands/auth.js +229 -0
  6. package/dist/commands/balanceAssignment.js +5 -12
  7. package/dist/commands/batch.js +226 -0
  8. package/dist/commands/clients.js +18 -79
  9. package/dist/commands/doctor.js +65 -66
  10. package/dist/commands/entries.js +5 -8
  11. package/dist/commands/expenses.js +29 -39
  12. package/dist/commands/helpers.js +68 -30
  13. package/dist/commands/invoices.js +3 -3
  14. package/dist/commands/leaf-command.js +7 -0
  15. package/dist/commands/manifest.js +63 -0
  16. package/dist/commands/operations.js +271 -0
  17. package/dist/commands/projects.js +17 -37
  18. package/dist/commands/reports.js +22 -7
  19. package/dist/commands/shared-report-body.js +14 -81
  20. package/dist/commands/sharedReports.js +8 -47
  21. package/dist/commands/skill.js +85 -0
  22. package/dist/commands/status.js +19 -13
  23. package/dist/commands/stop.js +3 -12
  24. package/dist/commands/tags.js +12 -21
  25. package/dist/commands/tasks.js +26 -134
  26. package/dist/commands/timeoff.js +1 -1
  27. package/dist/commands/users.js +4 -14
  28. package/dist/commands/webhook-delivery.js +331 -0
  29. package/dist/commands/webhooks.js +37 -110
  30. package/dist/completions.js +2 -1
  31. package/dist/config.js +166 -63
  32. package/dist/credentials.js +164 -0
  33. package/dist/failure.js +4 -9
  34. package/dist/flags.js +14 -4
  35. package/dist/generated/version.js +1 -1
  36. package/dist/index.js +38 -15
  37. package/dist/interrupts.js +28 -0
  38. package/dist/output.js +137 -48
  39. package/dist/receipt.js +2 -10
  40. package/dist/stdin.js +6 -0
  41. package/dist/stdout.js +38 -0
  42. package/dist/write-outcome.js +1 -1
  43. package/package.json +5 -3
  44. package/plugin/.claude-plugin/plugin.json +16 -0
  45. package/plugin/skills/clockify-cli/SKILL.md +88 -0
  46. package/plugin/skills/clockify-mcp/SKILL.md +48 -0
  47. package/plugin/skills/clockify-sdk/SKILL.md +85 -0
  48. package/dist/error-codes.js +0 -300
@@ -0,0 +1,271 @@
1
+ import { closeSync, openSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { Option } from "commander";
4
+ import { requireWorkspaceId } from "../config.js";
5
+ import { UsageError } from "../failure.js";
6
+ import { globalFlags, resolveFlags } from "../flags.js";
7
+ import { fixedColumns, printData, printObject, printRecords } from "../output.js";
8
+ import { printReceipt } from "../receipt.js";
9
+ import { dispatchedWrite } from "../write-outcome.js";
10
+ import { collect, parseIntArg, parseJson, parsePair, readTextInput, rootProgram } from "./helpers.js";
11
+ import { declareMutation, leafCommand } from "./leaf-command.js";
12
+ const EFFECTS = [
13
+ "read",
14
+ "business_write",
15
+ "external_side_effect",
16
+ "privileged",
17
+ "destructive",
18
+ ];
19
+ const LIST_KEYS = ["name", "effect", "method", "path", "command", "tool", "summary"];
20
+ const REQUEST_KEYS = ["ok", "dryRun", "operation", "effect", "method", "path", "query", "body"];
21
+ const WRITTEN_KEYS = ["written", "bytes"];
22
+ const OPERATION_KEYS = Object.keys({
23
+ name: true, operationId: true, method: true, path: true, service: true, server: true, tags: true, summary: true, description: true,
24
+ deprecated: true, effect: true, destructiveHint: true, openWorldHint: true, replacedBy: true, mcp: true, cli: true, media: true,
25
+ responseMedia: true, returnsSigningToken: true, input: true,
26
+ });
27
+ export async function requireOperation(reference) {
28
+ const { findOperation, searchOperations } = await import("clockify-sdk-ts-115/operations");
29
+ const operation = findOperation(reference);
30
+ if (operation !== undefined)
31
+ return operation;
32
+ const near = searchOperations(reference.replace(/[._-]/g, " ")).slice(0, 3).map(({ name }) => name);
33
+ throw new UsageError(`Unknown operation "${reference}". ` +
34
+ (near.length > 0 ? `Provide one of: ${near.join(", ")}.` : "Run `clk115 operations list`."));
35
+ }
36
+ export function resolvedRequest(operation, { workspaceId, path: params = {}, query, body }) {
37
+ const values = { ...params, workspaceId };
38
+ return {
39
+ operation: operation.name,
40
+ effect: operation.effect,
41
+ method: operation.method,
42
+ path: operation.path.replace(/\{(\w+)\}/g, (_, name) => encodeURIComponent(String(values[name]))),
43
+ ...(query && Object.keys(query).length > 0 && { query }),
44
+ ...(body !== undefined && { body: describeBody(body) }),
45
+ };
46
+ }
47
+ function describeBody(body) {
48
+ if (body instanceof Blob)
49
+ return `<${body.size} bytes>`;
50
+ if (Array.isArray(body))
51
+ return body.map(describeBody);
52
+ if (body === null || typeof body !== "object")
53
+ return body;
54
+ return Object.fromEntries(Object.entries(body).map(([key, value]) => [key, describeBody(value)]));
55
+ }
56
+ function coerce(schema, values) {
57
+ if (schema?.type === "array")
58
+ return values.map((value) => coerce(schema.items, [value]));
59
+ if (values.length > 1)
60
+ return values;
61
+ const value = values[0];
62
+ if ((schema?.type === "integer" || schema?.type === "number") && value.trim() !== "" && Number.isFinite(Number(value))) {
63
+ return Number(value);
64
+ }
65
+ if (schema?.type === "boolean" && (value === "true" || value === "false"))
66
+ return value === "true";
67
+ return value;
68
+ }
69
+ function parameters(schema, pairs) {
70
+ const values = new Map();
71
+ for (const [key, value] of pairs)
72
+ values.set(key, [...(values.get(key) ?? []), value]);
73
+ return Object.fromEntries([...values].map(([key, value]) => [key, coerce(schema?.properties?.[key], value)]));
74
+ }
75
+ function withFile(operation, body, file) {
76
+ if (file === undefined)
77
+ return body;
78
+ const fields = operation.input.properties?.body?.properties ?? {};
79
+ const field = Object.keys(fields).find((name) => fields[name].format === "binary");
80
+ if (field === undefined)
81
+ throw new UsageError(`--file does not apply: ${operation.name} takes no file.`);
82
+ let bytes;
83
+ try {
84
+ bytes = readFileSync(file);
85
+ }
86
+ catch (err) {
87
+ throw new UsageError(`--file ${JSON.stringify(file)} could not be read: ${err.message}; provide a readable file`);
88
+ }
89
+ return { ...body, [field]: new File([bytes], path.basename(file)) };
90
+ }
91
+ export const registerOperationsCommand = (program, services) => {
92
+ const operations = program
93
+ .command("operations")
94
+ .description("Find, inspect and call any of the API's operations.");
95
+ leafCommand(operations, "list", "read")
96
+ .description("List operations, or search them by what you want to do.")
97
+ .argument("[words...]", "What you want to do, for example: archive a client.")
98
+ .addOption(new Option("--effect <effect>", "Only operations with this effect.").choices(EFFECTS))
99
+ .option("--tag <tag>", "Only operations with this tag.")
100
+ .option("--limit <n>", "Maximum operations to print.", parseIntArg, 25)
101
+ .option("--all", "Print every match.", false)
102
+ .addHelpText("after", "\nExamples:\n" +
103
+ " $ clk115 operations list archive a client\n" +
104
+ " $ clk115 operations list --tag Invoices --effect read\n" +
105
+ " $ clk115 operations list --all --json\n")
106
+ .action(async function (words, opts) {
107
+ const output = fixedColumns(LIST_KEYS, resolveFlags(rootProgram(this)));
108
+ const catalog = await import("clockify-sdk-ts-115/operations");
109
+ const found = words.length > 0 ? catalog.searchOperations(words.join(" ")) : [...catalog.operations().values()];
110
+ const rows = found
111
+ .filter(({ effect }) => opts.effect === undefined || effect === opts.effect)
112
+ .filter(({ tags }) => opts.tag === undefined || tags.some((tag) => tag.toLowerCase() === opts.tag.toLowerCase()))
113
+ .slice(0, opts.all ? undefined : opts.limit)
114
+ .map(({ name, effect, method, path: route, cli, mcp, summary, deprecated }) => ({
115
+ name,
116
+ effect,
117
+ method,
118
+ path: route,
119
+ command: cli ?? null,
120
+ tool: mcp.curated ?? mcp.exact,
121
+ summary: (deprecated ? "Deprecated. " : "") + (summary ?? ""),
122
+ }));
123
+ const brief = output.mode === "table" && output.fields === undefined;
124
+ printRecords(brief ? rows.map(({ name, effect, command, summary }) => ({ name, effect, command, summary })) : rows, output);
125
+ });
126
+ leafCommand(operations, "show", "read")
127
+ .description("Show one operation: route, effect, input schema and the command or tool that covers it.")
128
+ .argument("<operation>", "Name (tags.create), operationId or exact MCP tool name.")
129
+ .addHelpText("after", "\nExamples:\n" + " $ clk115 operations show tags.create --json\n")
130
+ .action(async function (reference) {
131
+ const output = fixedColumns(OPERATION_KEYS, resolveFlags(rootProgram(this)));
132
+ const operation = await requireOperation(reference);
133
+ if (output.mode === "table" && output.fields === undefined) {
134
+ const { input, ...rest } = operation;
135
+ printObject(rest, output);
136
+ console.log(JSON.stringify(input, null, 2));
137
+ return;
138
+ }
139
+ printObject(operation, output);
140
+ });
141
+ leafCommand(operations, "call", "destructive")
142
+ .description("Call one operation. Input is checked against its schema before anything is sent.")
143
+ .argument("<operation>", "Name (tags.create), operationId or exact MCP tool name.")
144
+ .option("-p, --path <name=value>", "Path parameter (repeatable); workspaceId comes from the configuration.", collect, [])
145
+ .option("-q, --query <name=value>", "Query parameter (repeatable).", collect, [])
146
+ .option("--body <json|@file|->", "JSON body: inline, @file, or - for stdin.")
147
+ .option("--file <path>", "File to upload, for the operations that take one.")
148
+ .option("--output-file <path>", "Write the response to this new file instead of stdout.")
149
+ .option("--dry-run", "Print the request without sending it. Needs no credentials.", false)
150
+ .addHelpText("after", "\nExamples:\n" +
151
+ " $ clk115 operations call tags.list -q archived=false\n" +
152
+ " $ clk115 operations call tags.create --body '{\"name\":\"focus\"}' --dry-run\n" +
153
+ " $ clk115 operations call expenses.create --body @expense.json --file receipt.pdf\n" +
154
+ "\nAn operation that replaces a record resets the fields you leave out; `operations show` names the safe update.\n")
155
+ .action(async function (reference, opts) {
156
+ const operation = await requireOperation(reference);
157
+ const reads = operation.effect === "read";
158
+ declareMutation(this, !reads);
159
+ const { callOperation, operationInputProblems } = await import("clockify-sdk-ts-115/operations");
160
+ const root = rootProgram(this);
161
+ const output = resolveFlags(root);
162
+ const schema = operation.input.properties;
163
+ const text = await readTextInput(opts.body, "--body");
164
+ const body = withFile(operation, text === undefined ? undefined : parseJson(text, "--body"), opts.file);
165
+ const config = services.loadConfig(globalFlags(root));
166
+ const workspaceId = operation.path.includes("{workspaceId}") ? requireWorkspaceId(config) : undefined;
167
+ const input = {
168
+ workspaceId,
169
+ path: parameters(schema?.path, opts.path.map((pair) => parsePair(pair, "--path"))),
170
+ query: parameters(schema?.query, opts.query.map((pair) => parsePair(pair, "--query"))),
171
+ ...(body !== undefined && { body }),
172
+ };
173
+ const problems = operationInputProblems(operation, input);
174
+ if (problems.length > 0) {
175
+ throw new UsageError(`${operation.name}: ${problems.join("; ")}. Run \`clk115 operations show ${operation.name}\` for its input.`);
176
+ }
177
+ if (opts.dryRun) {
178
+ printObject({ ok: true, dryRun: true, ...resolvedRequest(operation, input) }, fixedColumns(REQUEST_KEYS, output));
179
+ return;
180
+ }
181
+ const { outputFile } = opts;
182
+ const shape = outputFile !== undefined && reads ? fixedColumns(WRITTEN_KEYS, output) : output;
183
+ const fileFitsStdout = !process.stdout.isTTY && output.mode === "table";
184
+ if (outputFile !== undefined)
185
+ requireNewFile(outputFile);
186
+ else if (answersWithFile(operation) && !fileFitsStdout)
187
+ throw new UsageError(IS_A_FILE);
188
+ const client = await services.buildClient(config, this);
189
+ const call = callOperation(client, operation.name, input);
190
+ const answer = reads ? await call : await dispatchedWrite(this, call);
191
+ const data = outputFile === undefined ? await responseData(operation, answer) : await written(outputFile, operation, answer);
192
+ if (Buffer.isBuffer(data)) {
193
+ if (!fileFitsStdout)
194
+ throw new Error(IS_A_FILE);
195
+ process.stdout.write(data);
196
+ }
197
+ else if (reads)
198
+ printData(data, shape);
199
+ else
200
+ printReceipt(operationReceipt(operation, input, data), output);
201
+ });
202
+ };
203
+ const IS_A_FILE = "The response is a file: pass --output-file, or redirect stdout without an output flag.";
204
+ export function answersWithFile({ responseMedia = [] }) {
205
+ return responseMedia.includes("application/octet-stream");
206
+ }
207
+ function isFileResponse(value) {
208
+ return value !== null && typeof value === "object" && "arrayBuffer" in value && typeof value.arrayBuffer === "function";
209
+ }
210
+ function withoutSigningToken({ returnsSigningToken }, data) {
211
+ if (!returnsSigningToken || data === undefined)
212
+ return data;
213
+ return JSON.parse(JSON.stringify(data, (key, value) => (key === "authToken" ? undefined : value)));
214
+ }
215
+ async function responseBytes(answer) {
216
+ return isFileResponse(answer) ? Buffer.from(await answer.arrayBuffer()) : answer;
217
+ }
218
+ export async function responseData(operation, answer) {
219
+ const { returnsSigningToken } = operation;
220
+ const raw = await responseBytes(answer);
221
+ const encoded = Buffer.isBuffer(raw) ? !answersWithFile(operation) : typeof raw === "string" && returnsSigningToken;
222
+ if (!encoded)
223
+ return withoutSigningToken(operation, raw);
224
+ try {
225
+ const text = new TextDecoder("utf-8", { fatal: true }).decode(Buffer.from(raw));
226
+ return withoutSigningToken(operation, JSON.parse(text));
227
+ }
228
+ catch {
229
+ if (returnsSigningToken)
230
+ throw new Error("The response is not JSON and may contain a signing token, so it is not shown.");
231
+ return raw;
232
+ }
233
+ }
234
+ function requireNewFile(file) {
235
+ try {
236
+ closeSync(openSync(file, "wx"));
237
+ rmSync(file);
238
+ }
239
+ catch (err) {
240
+ throw new UsageError(`--output-file ${JSON.stringify(file)} could not be created: ${err.message}; provide a path that does not exist yet`);
241
+ }
242
+ }
243
+ async function written(file, operation, answer) {
244
+ const data = isFileResponse(answer) && !operation.returnsSigningToken ? await responseBytes(answer) : await responseData(operation, answer);
245
+ const bytes = Buffer.isBuffer(data) ? data : Buffer.from(`${JSON.stringify(data ?? null, null, 2)}\n`);
246
+ const descriptor = openSync(file, "wx");
247
+ try {
248
+ writeFileSync(descriptor, bytes);
249
+ return { written: file, bytes: bytes.length };
250
+ }
251
+ catch (err) {
252
+ rmSync(file, { force: true });
253
+ throw err;
254
+ }
255
+ finally {
256
+ closeSync(descriptor);
257
+ }
258
+ }
259
+ export function operationReceipt(operation, { path: params = {} }, data) {
260
+ const ids = Object.fromEntries(Object.entries(params).map(([name, value]) => [name, String(value)]));
261
+ const record = data !== null && typeof data === "object" && !Array.isArray(data)
262
+ ? data
263
+ : data === undefined || data === null ? {} : { result: data };
264
+ return {
265
+ ok: true,
266
+ action: operation.name,
267
+ entity: operation.name.split(".")[0],
268
+ ids: { ...ids, ...(typeof record.id === "string" && { id: record.id }) },
269
+ data: record,
270
+ };
271
+ }
@@ -1,16 +1,11 @@
1
1
  import { archiveThenDeleteProject } from "clockify-sdk-ts-115/ensure";
2
+ import { projectUpdate } from "clockify-sdk-ts-115/updates";
2
3
  import { PartialDeleteError, UsageError } from "../failure.js";
3
4
  import { printObject, printRecords } from "../output.js";
4
5
  import { printReceipt } from "../receipt.js";
5
6
  import { dispatchedWrite } from "../write-outcome.js";
6
- import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
7
+ import { clampPageSize, parseIntArg, printDeleted, resolveContext } from "./helpers.js";
7
8
  import { leafCommand } from "./leaf-command.js";
8
- function projectUpdateCarryFields(current) {
9
- if (typeof current.billable !== "boolean" || typeof current.public !== "boolean") {
10
- throw new Error("Cannot update project safely: the current project did not return boolean billable and public fields.");
11
- }
12
- return { billable: current.billable, isPublic: current.public };
13
- }
14
9
  export const registerProjectsCommand = (program, services) => {
15
10
  const projects = program.command("projects").description("Manage projects.");
16
11
  leafCommand(projects, "list", "read")
@@ -70,7 +65,7 @@ export const registerProjectsCommand = (program, services) => {
70
65
  ...(opts.billable ? { billable: true } : {}),
71
66
  },
72
67
  };
73
- const created = (await dispatchedWrite(this, client.projects.create(req)));
68
+ const created = await dispatchedWrite(this, client.projects.create(req));
74
69
  const data = {
75
70
  id: created.id ?? "",
76
71
  name: created.name ?? "",
@@ -127,21 +122,16 @@ export const registerProjectsCommand = (program, services) => {
127
122
  }
128
123
  const { client, workspaceId, output } = await resolveContext(this, services);
129
124
  const current = await client.projects.get({ workspaceId, projectId: id });
130
- const body = projectUpdateCarryFields(current);
131
- if (opts.name)
132
- body.name = opts.name;
133
- if (opts.client)
134
- body.clientId = opts.client;
135
- if (opts.color)
136
- body.color = opts.color;
137
- if (opts.note !== undefined)
138
- body.note = opts.note;
139
- if (opts.billable !== undefined)
140
- body.billable = opts.billable;
141
- if (opts.archived !== undefined)
142
- body.archived = opts.archived;
125
+ const body = projectUpdate.body(current, {
126
+ name: opts.name || undefined,
127
+ clientId: opts.client || undefined,
128
+ color: opts.color || undefined,
129
+ note: opts.note,
130
+ billable: opts.billable,
131
+ archived: opts.archived,
132
+ });
143
133
  const req = { workspaceId, projectId: id, body };
144
- const updated = (await dispatchedWrite(this, client.projects.update(req)));
134
+ const updated = await dispatchedWrite(this, client.projects.update(req));
145
135
  const data = { id: updated.id ?? id, name: updated.name ?? "" };
146
136
  printReceipt({
147
137
  ok: true,
@@ -171,13 +161,10 @@ export const registerProjectsCommand = (program, services) => {
171
161
  adapter: {
172
162
  getCurrent: ({ workspaceId: currentWorkspaceId, id: projectId }) => client.projects.get({ workspaceId: currentWorkspaceId, projectId }),
173
163
  archive: async ({ workspaceId: currentWorkspaceId, id: projectId, current, }) => {
174
- const preserved = projectUpdateCarryFields(current);
175
164
  await dispatchedWrite(this, client.projects.update({
176
165
  workspaceId: currentWorkspaceId,
177
166
  projectId,
178
- name: current.name,
179
- ...preserved,
180
- archived: true,
167
+ ...projectUpdate.body(current, { name: current.name, archived: true }),
181
168
  }));
182
169
  archivedByCall = true;
183
170
  },
@@ -194,19 +181,12 @@ export const registerProjectsCommand = (program, services) => {
194
181
  },
195
182
  },
196
183
  });
197
- printReceipt({
198
- ok: true,
184
+ printDeleted(output, {
199
185
  action: "projects.delete",
200
186
  entity: "project",
187
+ id,
201
188
  ids: { projectId: id },
202
- data: { id, deleted: true, message: `deleted project ${id}` },
203
- changed: { deleted: [{ type: "project", id }] },
204
- next: [
205
- {
206
- command: "clk115 projects list --json",
207
- reason: "Verify the project no longer appears.",
208
- },
209
- ],
210
- }, output);
189
+ list: "projects list",
190
+ });
211
191
  });
212
192
  };
@@ -1,10 +1,20 @@
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
3
  import { UsageError } from "../failure.js";
4
- import { printObject } from "../output.js";
4
+ import { printData, printObject, printWarning } from "../output.js";
5
5
  import { clampPageSize, parseIntArg, parseTimeViewMode, resolveContext, TIME_VIEW_MODE_HELP } from "./helpers.js";
6
6
  import { leafCommand } from "./leaf-command.js";
7
7
  import { resolveClientId, resolveProjectId } from "./resolve-refs.js";
8
+ function printReport(report, lists, output) {
9
+ const answer = (report ?? { totals: [] });
10
+ const isReport = ["totals", ...lists].some((list) => Array.isArray(answer[list]));
11
+ const rows = lists.map((list) => answer[list]).find((list) => Array.isArray(list) && list.length > 0);
12
+ if (output.mode === "csv" && isReport)
13
+ printData(rows ?? [], output);
14
+ else
15
+ printObject(report, output);
16
+ return rows ?? [];
17
+ }
8
18
  function resolveRange(opts) {
9
19
  const now = new Date();
10
20
  const periodInput = (opts.period ?? "this_month")
@@ -161,7 +171,7 @@ export const registerReportsCommand = (program, services) => {
161
171
  req.clients = idFilter(ids);
162
172
  }
163
173
  const data = await client.reports.summary(req);
164
- printObject(data, output);
174
+ printReport(data, ["groupOne"], output);
165
175
  });
166
176
  leafCommand(reports, "detailed", "read")
167
177
  .description("Detailed report listing individual time entries over a date range.")
@@ -176,18 +186,23 @@ export const registerReportsCommand = (program, services) => {
176
186
  const timeViewMode = optionalTimeViewMode(opts);
177
187
  const { client, workspaceId, output } = await resolveContext(this, services);
178
188
  const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
189
+ const { page } = opts;
190
+ const pageSize = clampPageSize(opts.pageSize, 1000);
179
191
  const req = {
180
192
  workspaceId,
181
193
  dateRangeStart,
182
194
  dateRangeEnd,
183
195
  detailedFilter: detailedFilter({
184
- page: opts.page,
185
- pageSize: clampPageSize(opts.pageSize, 1000),
196
+ page,
197
+ pageSize,
186
198
  }),
187
199
  ...(timeViewMode !== undefined ? { timeViewMode } : {}),
188
200
  };
189
201
  const data = await client.reports.detailed(req);
190
- printObject(data, output);
202
+ const entries = printReport(data, ["timeentries", "timeEntries"], output);
203
+ if (entries.length >= pageSize) {
204
+ printWarning(`Page ${page} is full (${entries.length} entries). Read on with --page ${page + 1}.`, output);
205
+ }
191
206
  });
192
207
  leafCommand(reports, "weekly", "read")
193
208
  .description("Weekly report for one exact seven-day interval.")
@@ -211,7 +226,7 @@ export const registerReportsCommand = (program, services) => {
211
226
  ...(timeViewMode !== undefined ? { timeViewMode } : {}),
212
227
  };
213
228
  const data = await client.reports.weekly(req);
214
- printObject(data, output);
229
+ printReport(data, ["groupOne"], output);
215
230
  });
216
231
  leafCommand(reports, "attendance", "read")
217
232
  .description("Attendance report of clock-in/out activity over a date range.")
@@ -232,6 +247,6 @@ export const registerReportsCommand = (program, services) => {
232
247
  ...(timeViewMode !== undefined ? { timeViewMode } : {}),
233
248
  };
234
249
  const data = await client.reports.attendance(req);
235
- printObject(data, output);
250
+ printReport(data, ["groupOne", "entities"], output);
236
251
  });
237
252
  };
@@ -1,6 +1,18 @@
1
+ import { defined, SHARED_REPORT_TYPES, } from "clockify-sdk-ts-115/requests";
1
2
  import { z } from "zod";
2
3
  import { UsageError } from "../failure.js";
3
- import { SHARED_REPORT_FILTER_EXPORT_TYPES, SHARED_REPORT_TYPES, SUMMARY_GROUPS, } from "./sharedReports.js";
4
+ const SHARED_REPORT_FILTER_EXPORT_TYPES = ["JSON_V1", "JSON", "CSV", "XLSX", "PDF"];
5
+ const SUMMARY_GROUPS = [
6
+ "CLIENT",
7
+ "PROJECT",
8
+ "TASK",
9
+ "DATE",
10
+ "WEEK",
11
+ "MONTH",
12
+ "TIMEENTRY",
13
+ "USER",
14
+ "TAG",
15
+ ];
4
16
  const nonEmptyStringSchema = z
5
17
  .string()
6
18
  .refine((value) => value.trim() !== "", "must be a non-empty string.");
@@ -68,85 +80,6 @@ const sharedReportBodySchema = z
68
80
  type: sharedReportTypeSchema,
69
81
  })
70
82
  .strict();
71
- function toSharedUsersFilter(value) {
72
- return {
73
- ...(value.contains !== undefined ? { contains: value.contains } : {}),
74
- ...(value.ids !== undefined ? { ids: value.ids } : {}),
75
- ...(value.status !== undefined ? { status: value.status } : {}),
76
- };
77
- }
78
- function toSharedReportFilter(value) {
79
- return {
80
- dateRangeEnd: value.dateRangeEnd,
81
- dateRangeStart: value.dateRangeStart,
82
- exportType: value.exportType,
83
- ...(value.attendanceFilter !== undefined
84
- ? {
85
- attendanceFilter: {
86
- ...(value.attendanceFilter.page !== undefined
87
- ? { page: value.attendanceFilter.page }
88
- : {}),
89
- ...(value.attendanceFilter.pageSize !== undefined
90
- ? { pageSize: value.attendanceFilter.pageSize }
91
- : {}),
92
- ...(value.attendanceFilter.users !== undefined
93
- ? { users: toSharedUsersFilter(value.attendanceFilter.users) }
94
- : {}),
95
- },
96
- }
97
- : {}),
98
- ...(value.detailedFilter !== undefined
99
- ? {
100
- detailedFilter: {
101
- ...(value.detailedFilter.auditFilter !== undefined
102
- ? { auditFilter: value.detailedFilter.auditFilter }
103
- : {}),
104
- ...(value.detailedFilter.options !== undefined
105
- ? { options: value.detailedFilter.options }
106
- : {}),
107
- ...(value.detailedFilter.page !== undefined
108
- ? { page: value.detailedFilter.page }
109
- : {}),
110
- ...(value.detailedFilter.pageSize !== undefined
111
- ? { pageSize: value.detailedFilter.pageSize }
112
- : {}),
113
- ...(value.detailedFilter.sortColumn !== undefined
114
- ? { sortColumn: value.detailedFilter.sortColumn }
115
- : {}),
116
- ...(value.detailedFilter.sortOrder !== undefined
117
- ? { sortOrder: value.detailedFilter.sortOrder }
118
- : {}),
119
- },
120
- }
121
- : {}),
122
- ...(value.summaryFilter !== undefined
123
- ? {
124
- summaryFilter: {
125
- groups: value.summaryFilter.groups,
126
- ...(value.summaryFilter.sortColumn !== undefined
127
- ? { sortColumn: value.summaryFilter.sortColumn }
128
- : {}),
129
- },
130
- }
131
- : {}),
132
- ...(value.weeklyFilter !== undefined
133
- ? {
134
- weeklyFilter: {
135
- group: value.weeklyFilter.group,
136
- subgroup: value.weeklyFilter.subgroup,
137
- },
138
- }
139
- : {}),
140
- };
141
- }
142
- function toSharedReportBody(value) {
143
- return {
144
- filter: toSharedReportFilter(value.filter),
145
- name: value.name,
146
- type: value.type,
147
- ...(value.isPublic !== undefined ? { isPublic: value.isPublic } : {}),
148
- };
149
- }
150
83
  function parseFilterJson(raw) {
151
84
  if (typeof raw !== "string") {
152
85
  throw new UsageError("--filter must be a JSON object.");
@@ -201,5 +134,5 @@ export function parseSharedReportBody(opts, operation) {
201
134
  if (!result.success) {
202
135
  throw sharedReportValidationError(result.error, operation, opts.type);
203
136
  }
204
- return toSharedReportBody(result.data);
137
+ return defined(result.data);
205
138
  }
@@ -1,8 +1,9 @@
1
+ import { SHARED_REPORT_TYPES } from "clockify-sdk-ts-115/requests";
1
2
  import { UsageError } from "../failure.js";
2
3
  import { printObject, printRecords } from "../output.js";
3
4
  import { printReceipt } from "../receipt.js";
4
5
  import { dispatchedWrite } from "../write-outcome.js";
5
- import { parseTimeViewMode, resolveBaseContext, resolveContext, TIME_VIEW_MODE_HELP } from "./helpers.js";
6
+ import { parseTimeViewMode, printDeleted, resolveBaseContext, resolveContext, TIME_VIEW_MODE_HELP, } from "./helpers.js";
6
7
  import { leafCommand } from "./leaf-command.js";
7
8
  async function readReportBody(response) {
8
9
  const buffer = await response.arrayBuffer();
@@ -20,40 +21,7 @@ async function readReportBody(response) {
20
21
  return { body: text };
21
22
  }
22
23
  }
23
- export const SHARED_REPORT_TYPES = [
24
- "SUMMARY",
25
- "DETAILED",
26
- "WEEKLY",
27
- "EXPENSE_DETAILED",
28
- "INVOICE_TIME",
29
- "KIOSK_PIN_LIST",
30
- "ATTENDANCE_DETAILED",
31
- "ATTENDANCE_SUMMARY",
32
- "ASSIGNMENT_LIST",
33
- "ASSIGNMENT_SCHEDULE",
34
- "APPROVAL_DETAILED",
35
- "APPROVAL_SUMMARY",
36
- "BALANCE_LIST",
37
- "INVOICE_AMOUNT_LIST",
38
- "INVOICE_DETAILED",
39
- "TIMEOFF_DETAILED",
40
- "TIMEOFF_HOLIDAY",
41
- "TIMEOFF_BALANCE",
42
- "EXPENSE_SUMMARY",
43
- ];
44
- export const SHARED_REPORT_FILTER_EXPORT_TYPES = ["JSON_V1", "JSON", "CSV", "XLSX", "PDF"];
45
24
  const SHARED_REPORT_VIEW_EXPORT_TYPES = ["JSON_V1", "JSON", "CSV"];
46
- export const SUMMARY_GROUPS = [
47
- "CLIENT",
48
- "PROJECT",
49
- "TASK",
50
- "DATE",
51
- "WEEK",
52
- "MONTH",
53
- "TIMEENTRY",
54
- "USER",
55
- "TAG",
56
- ];
57
25
  export const registerSharedReportsCommand = (program, services) => {
58
26
  const shared = program
59
27
  .command("shared-reports")
@@ -114,7 +82,7 @@ export const registerSharedReportsCommand = (program, services) => {
114
82
  const body = parseSharedReportBody(opts, "shared-reports.create");
115
83
  const { client, workspaceId, output } = await resolveContext(this, services);
116
84
  const request = { workspaceId, body };
117
- const created = (await dispatchedWrite(this, client.sharedReports.create(request)));
85
+ const created = await dispatchedWrite(this, client.sharedReports.create(request));
118
86
  const data = { id: created.id ?? "", name: created.name ?? opts.name };
119
87
  printReceipt({
120
88
  ok: true,
@@ -151,7 +119,7 @@ export const registerSharedReportsCommand = (program, services) => {
151
119
  sharedReportId: id,
152
120
  body,
153
121
  };
154
- const updated = (await dispatchedWrite(this, client.sharedReports.update(request)));
122
+ const updated = await dispatchedWrite(this, client.sharedReports.update(request));
155
123
  const data = { id: updated.id ?? id, name: updated.name ?? opts.name };
156
124
  printReceipt({
157
125
  ok: true,
@@ -175,19 +143,12 @@ export const registerSharedReportsCommand = (program, services) => {
175
143
  .action(async function (id) {
176
144
  const { client, workspaceId, output } = await resolveContext(this, services);
177
145
  await dispatchedWrite(this, client.sharedReports.delete({ workspaceId, sharedReportId: id }));
178
- printReceipt({
179
- ok: true,
146
+ printDeleted(output, {
180
147
  action: "shared-reports.delete",
181
148
  entity: "shared_report",
149
+ id,
182
150
  ids: { sharedReportId: id },
183
- data: { id, deleted: true, message: `deleted shared report ${id}` },
184
- changed: { deleted: [{ type: "shared_report", id }] },
185
- next: [
186
- {
187
- command: "clk115 shared-reports list --json",
188
- reason: "Verify the report no longer appears.",
189
- },
190
- ],
191
- }, output);
151
+ list: "shared-reports list",
152
+ });
192
153
  });
193
154
  };