@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.
- package/README.md +32 -15
- package/dist/client.js +3 -3
- package/dist/commands/api.js +26 -20
- package/dist/commands/approvals.js +95 -0
- package/dist/commands/auditlog.js +13 -9
- package/dist/commands/balanceAssignment.js +149 -0
- package/dist/commands/clients.js +2 -2
- package/dist/commands/doctor.js +21 -4
- package/dist/commands/entries.js +28 -3
- package/dist/commands/helpers.js +9 -2
- package/dist/commands/invoices.js +22 -13
- package/dist/commands/log.js +1 -1
- package/dist/commands/projects.js +19 -1
- package/dist/commands/reports.js +24 -9
- package/dist/commands/resolve-refs.js +2 -2
- package/dist/commands/scheduling.js +2 -2
- package/dist/commands/sharedReports.js +41 -19
- package/dist/commands/start.js +0 -6
- package/dist/commands/stop.js +9 -2
- package/dist/commands/tags.js +3 -0
- package/dist/commands/tasks.js +8 -4
- package/dist/commands/timeoff.js +12 -5
- package/dist/commands/users.js +33 -9
- package/dist/commands/webhooks.js +6 -6
- package/dist/completions.js +1 -0
- package/dist/config.js +15 -14
- package/dist/duration.js +3 -3
- package/dist/generated/version.js +1 -1
- package/dist/index.js +30 -7
- package/package.json +5 -5
package/dist/commands/entries.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { entityId } from "clockify-sdk-ts-115/operation-receipt";
|
|
2
2
|
import { printRecords } from "../output.js";
|
|
3
3
|
import { printReceipt } from "../receipt.js";
|
|
4
|
-
import { clampPageSize, parseIntArg, promoteDateBoundary, resolveContext } from "./helpers.js";
|
|
4
|
+
import { clampPageSize, parseIntArg, promoteDateBoundary, resolveContext, splitList, } from "./helpers.js";
|
|
5
5
|
import { leafCommand } from "./leaf-command.js";
|
|
6
6
|
export const registerEntriesCommand = (program, services) => {
|
|
7
7
|
const entries = program.command("entries").description("Manage time entries.");
|
|
@@ -9,8 +9,8 @@ export const registerEntriesCommand = (program, services) => {
|
|
|
9
9
|
.description("List the current user's time entries.")
|
|
10
10
|
.option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
|
|
11
11
|
.option("--page <n>", "Page number (default 1).", parseIntArg, 1)
|
|
12
|
-
.option("--from <date>", "
|
|
13
|
-
.option("--to <date>", "
|
|
12
|
+
.option("--from <date>", "Inclusive start bound (YYYY-MM-DD or RFC3339).")
|
|
13
|
+
.option("--to <date>", "Inclusive end bound (YYYY-MM-DD or RFC3339).")
|
|
14
14
|
.option("--description <text>", "Filter by description substring.")
|
|
15
15
|
.action(async function (opts) {
|
|
16
16
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
@@ -47,6 +47,31 @@ export const registerEntriesCommand = (program, services) => {
|
|
|
47
47
|
});
|
|
48
48
|
printRecords(rows, output);
|
|
49
49
|
});
|
|
50
|
+
leafCommand(entries, "get-many", "read")
|
|
51
|
+
.description("Look up several time entries by ID in one call.")
|
|
52
|
+
.requiredOption("--ids <ids>", "Comma-separated time-entry IDs.")
|
|
53
|
+
.option("--hydrated", "Include project, task, and tag detail.", false)
|
|
54
|
+
.action(async function (opts) {
|
|
55
|
+
const timeEntryIds = splitList(opts.ids);
|
|
56
|
+
if (timeEntryIds.length === 0)
|
|
57
|
+
throw new Error("--ids needs at least one time-entry ID");
|
|
58
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
59
|
+
const items = await client.timeEntries.getMultipleTimeEntries({
|
|
60
|
+
workspaceId,
|
|
61
|
+
body: { timeEntryIds, hydrated: opts.hydrated === true },
|
|
62
|
+
});
|
|
63
|
+
const rows = items.map((entry) => ({
|
|
64
|
+
id: entry.id ?? "",
|
|
65
|
+
description: entry.description ?? "",
|
|
66
|
+
project: entry.projectId ?? "",
|
|
67
|
+
task: entry.taskId ?? "",
|
|
68
|
+
billable: entry.billable === true,
|
|
69
|
+
start: entry.timeInterval?.start ?? "",
|
|
70
|
+
end: entry.timeInterval?.end ?? "",
|
|
71
|
+
duration: entry.timeInterval?.duration ?? "",
|
|
72
|
+
}));
|
|
73
|
+
printRecords(rows, output);
|
|
74
|
+
});
|
|
50
75
|
leafCommand(entries, "delete", "destructive")
|
|
51
76
|
.argument("<id>", "Time-entry ID.")
|
|
52
77
|
.description("Delete a time entry by ID.")
|
package/dist/commands/helpers.js
CHANGED
|
@@ -15,6 +15,13 @@ export function parseFloatArg(value) {
|
|
|
15
15
|
}
|
|
16
16
|
return parsed;
|
|
17
17
|
}
|
|
18
|
+
export function parseSignedFloatArg(value) {
|
|
19
|
+
const parsed = Number.parseFloat(value);
|
|
20
|
+
if (!Number.isFinite(parsed)) {
|
|
21
|
+
throw new InvalidArgumentError("must be a number.");
|
|
22
|
+
}
|
|
23
|
+
return parsed;
|
|
24
|
+
}
|
|
18
25
|
export function clampPageSize(value, max) {
|
|
19
26
|
return Math.min(value, max);
|
|
20
27
|
}
|
|
@@ -28,12 +35,12 @@ export function promoteDateBoundary(value, flag, edge) {
|
|
|
28
35
|
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
29
36
|
const probe = new Date(`${value}T00:00:00Z`);
|
|
30
37
|
if (Number.isNaN(probe.getTime()) || probe.toISOString().slice(0, 10) !== value) {
|
|
31
|
-
throw new Error(`--${flag} ${JSON.stringify(value)} is not a valid calendar date (YYYY-MM-DD)`);
|
|
38
|
+
throw new Error(`--${flag} ${JSON.stringify(value)} is not a valid calendar date (YYYY-MM-DD); provide a real calendar date`);
|
|
32
39
|
}
|
|
33
40
|
return edge === "start" ? `${value}T00:00:00Z` : `${value}T23:59:59Z`;
|
|
34
41
|
}
|
|
35
42
|
if (Number.isNaN(Date.parse(value))) {
|
|
36
|
-
throw new Error(`--${flag} ${JSON.stringify(value)} is not a valid date (YYYY-MM-DD) or RFC3339 timestamp`);
|
|
43
|
+
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`);
|
|
37
44
|
}
|
|
38
45
|
return value;
|
|
39
46
|
}
|
|
@@ -1,14 +1,24 @@
|
|
|
1
1
|
import { printRecords } from "../output.js";
|
|
2
2
|
import { printReceipt } from "../receipt.js";
|
|
3
|
-
import { resolveContext } from "./helpers.js";
|
|
3
|
+
import { clampPageSize, parseIntArg, promoteDateBoundary, resolveContext } from "./helpers.js";
|
|
4
4
|
import { leafCommand } from "./leaf-command.js";
|
|
5
|
+
const TIME_VIEW_MODES = [
|
|
6
|
+
"TIME_SENSITIVE_VIEW",
|
|
7
|
+
"AGGREGATED_TIME_VIEW",
|
|
8
|
+
];
|
|
5
9
|
export const registerInvoicesCommand = (program, services) => {
|
|
6
10
|
const invoices = program.command("invoices").description("Manage invoices.");
|
|
7
11
|
leafCommand(invoices, "list", "read")
|
|
8
12
|
.description("List invoices in the workspace.")
|
|
9
|
-
.
|
|
13
|
+
.option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
|
|
14
|
+
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
15
|
+
.action(async function (opts) {
|
|
10
16
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
11
|
-
const response = (await client.invoices.list({
|
|
17
|
+
const response = (await client.invoices.list({
|
|
18
|
+
workspaceId,
|
|
19
|
+
page: opts.page,
|
|
20
|
+
"page-size": clampPageSize(opts.limit, 200),
|
|
21
|
+
}));
|
|
12
22
|
const items = response.invoices ?? [];
|
|
13
23
|
const rows = items.map((raw) => {
|
|
14
24
|
const inv = raw;
|
|
@@ -32,7 +42,7 @@ export const registerInvoicesCommand = (program, services) => {
|
|
|
32
42
|
.requiredOption("--currency <code>", "ISO currency code (e.g. USD, EUR).")
|
|
33
43
|
.requiredOption("--issued <date>", "Issued date (YYYY-MM-DD or RFC3339).")
|
|
34
44
|
.requiredOption("--due <date>", "Due date (YYYY-MM-DD or RFC3339).")
|
|
35
|
-
.option("--time-view-mode <mode>", "Time view mode
|
|
45
|
+
.option("--time-view-mode <mode>", "Time view mode: TIME_SENSITIVE_VIEW or AGGREGATED_TIME_VIEW.")
|
|
36
46
|
.action(async function (opts) {
|
|
37
47
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
38
48
|
const body = {
|
|
@@ -42,8 +52,13 @@ export const registerInvoicesCommand = (program, services) => {
|
|
|
42
52
|
issuedDate: normaliseInvoiceDate(opts.issued, "issued"),
|
|
43
53
|
dueDate: normaliseInvoiceDate(opts.due, "due"),
|
|
44
54
|
};
|
|
45
|
-
if (opts.timeViewMode)
|
|
46
|
-
|
|
55
|
+
if (opts.timeViewMode !== undefined) {
|
|
56
|
+
const mode = String(opts.timeViewMode).toUpperCase();
|
|
57
|
+
if (!TIME_VIEW_MODES.includes(mode)) {
|
|
58
|
+
throw new Error(`Unknown --time-view-mode "${String(opts.timeViewMode)}". Provide one of: ${TIME_VIEW_MODES.join(", ")}.`);
|
|
59
|
+
}
|
|
60
|
+
body.timeViewMode = mode;
|
|
61
|
+
}
|
|
47
62
|
const req = { workspaceId, body };
|
|
48
63
|
const created = (await client.invoices.create(req));
|
|
49
64
|
const data = {
|
|
@@ -70,11 +85,5 @@ export const registerInvoicesCommand = (program, services) => {
|
|
|
70
85
|
});
|
|
71
86
|
};
|
|
72
87
|
function normaliseInvoiceDate(value, label) {
|
|
73
|
-
|
|
74
|
-
throw new Error(`--${label} is required`);
|
|
75
|
-
}
|
|
76
|
-
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
|
|
77
|
-
return `${value}T00:00:00Z`;
|
|
78
|
-
}
|
|
79
|
-
return value;
|
|
88
|
+
return promoteDateBoundary(value, label, "start");
|
|
80
89
|
}
|
package/dist/commands/log.js
CHANGED
|
@@ -31,7 +31,7 @@ export const registerLogCommand = (program, services) => {
|
|
|
31
31
|
const endInput = opts.end ?? new Date().toISOString();
|
|
32
32
|
const endMs = Date.parse(endInput);
|
|
33
33
|
if (Number.isNaN(endMs)) {
|
|
34
|
-
throw new Error(`--end ${JSON.stringify(opts.end)} is not a valid ISO 8601 timestamp`);
|
|
34
|
+
throw new Error(`--end ${JSON.stringify(opts.end)} is not a valid ISO 8601 timestamp; provide an RFC3339 timestamp`);
|
|
35
35
|
}
|
|
36
36
|
const endIso = new Date(endMs).toISOString();
|
|
37
37
|
const startIso = new Date(endMs - seconds * 1000).toISOString();
|
|
@@ -3,6 +3,12 @@ import { printObject, printRecords } from "../output.js";
|
|
|
3
3
|
import { printReceipt } from "../receipt.js";
|
|
4
4
|
import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
|
|
5
5
|
import { leafCommand } from "./leaf-command.js";
|
|
6
|
+
function projectUpdateCarryFields(current) {
|
|
7
|
+
if (typeof current.billable !== "boolean" || typeof current.public !== "boolean") {
|
|
8
|
+
throw new Error("Cannot update project safely: the current project did not return boolean billable and public fields.");
|
|
9
|
+
}
|
|
10
|
+
return { billable: current.billable, isPublic: current.public };
|
|
11
|
+
}
|
|
6
12
|
export const registerProjectsCommand = (program, services) => {
|
|
7
13
|
const projects = program.command("projects").description("Manage projects.");
|
|
8
14
|
leafCommand(projects, "list", "read")
|
|
@@ -98,8 +104,18 @@ export const registerProjectsCommand = (program, services) => {
|
|
|
98
104
|
.option("--no-archived", "Unarchive the project.")
|
|
99
105
|
.description("Update a project by ID.")
|
|
100
106
|
.action(async function (id, opts) {
|
|
107
|
+
const hasChanges = Boolean(opts.name) ||
|
|
108
|
+
Boolean(opts.client) ||
|
|
109
|
+
Boolean(opts.color) ||
|
|
110
|
+
opts.note !== undefined ||
|
|
111
|
+
opts.billable !== undefined ||
|
|
112
|
+
opts.archived !== undefined;
|
|
113
|
+
if (!hasChanges) {
|
|
114
|
+
throw new Error("projects.update needs a change: provide at least one project field.");
|
|
115
|
+
}
|
|
101
116
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
102
|
-
const
|
|
117
|
+
const current = await client.projects.get({ workspaceId, projectId: id });
|
|
118
|
+
const body = projectUpdateCarryFields(current);
|
|
103
119
|
if (opts.name)
|
|
104
120
|
body.name = opts.name;
|
|
105
121
|
if (opts.client)
|
|
@@ -141,10 +157,12 @@ export const registerProjectsCommand = (program, services) => {
|
|
|
141
157
|
adapter: {
|
|
142
158
|
getCurrent: ({ workspaceId: currentWorkspaceId, id: projectId }) => client.projects.get({ workspaceId: currentWorkspaceId, projectId }),
|
|
143
159
|
archive: async ({ workspaceId: currentWorkspaceId, id: projectId, current, }) => {
|
|
160
|
+
const preserved = projectUpdateCarryFields(current);
|
|
144
161
|
await client.projects.update({
|
|
145
162
|
workspaceId: currentWorkspaceId,
|
|
146
163
|
projectId,
|
|
147
164
|
name: current.name,
|
|
165
|
+
...preserved,
|
|
148
166
|
archived: true,
|
|
149
167
|
});
|
|
150
168
|
},
|
package/dist/commands/reports.js
CHANGED
|
@@ -11,24 +11,37 @@ function resolveRange(opts) {
|
|
|
11
11
|
.toLowerCase()
|
|
12
12
|
.replace(/[\s-]+/g, "_");
|
|
13
13
|
if (!REPORT_PERIODS.includes(periodInput)) {
|
|
14
|
-
throw new Error(`Unknown --period "${opts.period}".
|
|
14
|
+
throw new Error(`Unknown --period "${opts.period}". Provide one of: ${REPORT_PERIODS.join(", ")}.`);
|
|
15
15
|
}
|
|
16
16
|
const range = resolvePeriod(now, periodInput);
|
|
17
17
|
let { dateRangeStart, dateRangeEnd } = range;
|
|
18
18
|
if (opts.from) {
|
|
19
19
|
const start = resolveInstant(now, opts.from, "start");
|
|
20
20
|
if (!start)
|
|
21
|
-
throw new Error(`--from "${opts.from}" is not a valid date, ISO timestamp, or period.`);
|
|
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
22
|
dateRangeStart = start;
|
|
23
23
|
}
|
|
24
24
|
if (opts.to) {
|
|
25
25
|
const end = resolveInstant(now, opts.to, "end");
|
|
26
26
|
if (!end)
|
|
27
|
-
throw new Error(`--to "${opts.to}" is not a valid date, ISO timestamp, or period.`);
|
|
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
28
|
dateRangeEnd = end;
|
|
29
29
|
}
|
|
30
30
|
return { dateRangeStart, dateRangeEnd };
|
|
31
31
|
}
|
|
32
|
+
function assertWeeklyRange(dateRangeStart, dateRangeEnd) {
|
|
33
|
+
const start = new Date(dateRangeStart);
|
|
34
|
+
const end = new Date(dateRangeEnd);
|
|
35
|
+
if (Number.isNaN(start.getTime()) || Number.isNaN(end.getTime())) {
|
|
36
|
+
throw new Error("Weekly reports require valid dateRangeStart and dateRangeEnd values.");
|
|
37
|
+
}
|
|
38
|
+
const elapsedMs = end.getTime() - start.getTime();
|
|
39
|
+
const exclusiveWeekMs = 7 * 86_400_000;
|
|
40
|
+
const inclusiveWeekMs = exclusiveWeekMs - 1;
|
|
41
|
+
if (elapsedMs !== exclusiveWeekMs && elapsedMs !== inclusiveWeekMs) {
|
|
42
|
+
throw new Error("Weekly reports require one exact seven-day interval (exclusive end) or its inclusive end-of-day equivalent. Provide --from and --to for one Monday-Sunday window or use --period last_week.");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
32
45
|
function idFilter(ids) {
|
|
33
46
|
return { ids, contains: "CONTAINS" };
|
|
34
47
|
}
|
|
@@ -41,6 +54,7 @@ const SUMMARY_GROUPS = [
|
|
|
41
54
|
"MONTH",
|
|
42
55
|
"TIMEENTRY",
|
|
43
56
|
"TASK",
|
|
57
|
+
"TAG",
|
|
44
58
|
];
|
|
45
59
|
function parseSummaryGroups(raw) {
|
|
46
60
|
const groups = String(raw)
|
|
@@ -48,25 +62,25 @@ function parseSummaryGroups(raw) {
|
|
|
48
62
|
.map((group) => group.trim().toUpperCase())
|
|
49
63
|
.filter(Boolean);
|
|
50
64
|
if (groups.length === 0 || groups.length > 3) {
|
|
51
|
-
throw new Error(
|
|
65
|
+
throw new Error(`--groups must contain between one and three summary groups; provide 1-3 of: ${SUMMARY_GROUPS.join(", ")}.`);
|
|
52
66
|
}
|
|
53
67
|
const unknown = groups.find((group) => !SUMMARY_GROUPS.includes(group));
|
|
54
68
|
if (unknown) {
|
|
55
|
-
throw new Error(`Unknown summary group: ${unknown}.
|
|
69
|
+
throw new Error(`Unknown summary group: ${unknown}. Provide one of: ${SUMMARY_GROUPS.join(", ")}.`);
|
|
56
70
|
}
|
|
57
71
|
return groups;
|
|
58
72
|
}
|
|
59
73
|
function parseWeeklyGroup(raw) {
|
|
60
74
|
const group = String(raw).toUpperCase();
|
|
61
75
|
if (group !== "USER" && group !== "PROJECT") {
|
|
62
|
-
throw new Error("
|
|
76
|
+
throw new Error("Unknown --group for the weekly report. Provide one of: USER, PROJECT.");
|
|
63
77
|
}
|
|
64
78
|
return group;
|
|
65
79
|
}
|
|
66
80
|
function parseWeeklySubgroup(raw) {
|
|
67
81
|
const subgroup = String(raw).toUpperCase();
|
|
68
82
|
if (subgroup !== "TIME") {
|
|
69
|
-
throw new Error("
|
|
83
|
+
throw new Error("Unknown --subgroup for the weekly report. Provide one of: TIME.");
|
|
70
84
|
}
|
|
71
85
|
return subgroup;
|
|
72
86
|
}
|
|
@@ -128,8 +142,8 @@ export const registerReportsCommand = (program, services) => {
|
|
|
128
142
|
printObject(data, output);
|
|
129
143
|
});
|
|
130
144
|
leafCommand(reports, "weekly", "read")
|
|
131
|
-
.description("Weekly report
|
|
132
|
-
.option("--period <p>",
|
|
145
|
+
.description("Weekly report for one exact seven-day interval.")
|
|
146
|
+
.option("--period <p>", "Named period (default last_week).", "last_week")
|
|
133
147
|
.option("--from <date>", "Range start; overrides --period.")
|
|
134
148
|
.option("--to <date>", "Range end; overrides --period.")
|
|
135
149
|
.option("--group <group>", "Top grouping: USER or PROJECT.", "USER")
|
|
@@ -137,6 +151,7 @@ export const registerReportsCommand = (program, services) => {
|
|
|
137
151
|
.action(async function (opts) {
|
|
138
152
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
139
153
|
const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
|
|
154
|
+
assertWeeklyRange(dateRangeStart, dateRangeEnd);
|
|
140
155
|
const req = {
|
|
141
156
|
workspaceId,
|
|
142
157
|
dateRangeStart,
|
|
@@ -13,7 +13,7 @@ function asNamed(rows) {
|
|
|
13
13
|
function pickIdByName(rows, ref, noun) {
|
|
14
14
|
const match = matchByName(asNamed(rows), ref);
|
|
15
15
|
if (match.kind === "many") {
|
|
16
|
-
throw new Error(`multiple ${noun}s named ${JSON.stringify(ref)};
|
|
16
|
+
throw new Error(`multiple ${noun}s named ${JSON.stringify(ref)}; provide the 24-character id instead`);
|
|
17
17
|
}
|
|
18
18
|
if (match.kind === "none") {
|
|
19
19
|
throw new Error(`${noun} ${JSON.stringify(ref)} not found in workspace`);
|
|
@@ -55,7 +55,7 @@ export async function resolveTaskId(client, workspaceId, projectId, ref) {
|
|
|
55
55
|
});
|
|
56
56
|
const match = matchByName(asNamed(list), ref);
|
|
57
57
|
if (match.kind === "many") {
|
|
58
|
-
throw new Error(`multiple tasks named ${JSON.stringify(ref)} on project ${projectId};
|
|
58
|
+
throw new Error(`multiple tasks named ${JSON.stringify(ref)} on project ${projectId}; provide the 24-character id`);
|
|
59
59
|
}
|
|
60
60
|
if (match.kind === "none") {
|
|
61
61
|
throw new Error(`task ${JSON.stringify(ref)} not found on project ${projectId}`);
|
|
@@ -45,8 +45,8 @@ export const registerSchedulingCommand = (program, services) => {
|
|
|
45
45
|
.description("Create a scheduling assignment (defaults to draft; pass --publish to publish).")
|
|
46
46
|
.requiredOption("--user <id>", "User ID to assign.")
|
|
47
47
|
.requiredOption("--project <id>", "Project ID.")
|
|
48
|
-
.requiredOption("--start <date>", "Period start (
|
|
49
|
-
.requiredOption("--end <date>", "Period end (
|
|
48
|
+
.requiredOption("--start <date>", "Period start (RFC3339, e.g. 2026-05-01T00:00:00Z).")
|
|
49
|
+
.requiredOption("--end <date>", "Period end (RFC3339, e.g. 2026-05-05T00:00:00Z).")
|
|
50
50
|
.requiredOption("--hours-per-day <n>", "Daily hour load (e.g. 6).", parseFloatArg)
|
|
51
51
|
.option("--task <id>", "Task ID.")
|
|
52
52
|
.option("--note <text>", "Assignment note.")
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import { printObject } from "../output.js";
|
|
2
|
+
import { printObject, printRecords } from "../output.js";
|
|
3
3
|
import { printReceipt } from "../receipt.js";
|
|
4
|
-
import { resolveContext } from "./helpers.js";
|
|
4
|
+
import { resolveBaseContext, resolveContext } from "./helpers.js";
|
|
5
5
|
import { leafCommand } from "./leaf-command.js";
|
|
6
6
|
async function readReportBody(response) {
|
|
7
|
-
const
|
|
7
|
+
const buffer = await response.arrayBuffer();
|
|
8
|
+
const text = new TextDecoder().decode(buffer);
|
|
8
9
|
if (!text)
|
|
9
10
|
return { body: "" };
|
|
10
11
|
try {
|
|
@@ -39,7 +40,8 @@ const SHARED_REPORT_TYPES = [
|
|
|
39
40
|
"TIMEOFF_BALANCE",
|
|
40
41
|
"EXPENSE_SUMMARY",
|
|
41
42
|
];
|
|
42
|
-
const
|
|
43
|
+
const SHARED_REPORT_FILTER_EXPORT_TYPES = ["JSON_V1", "JSON", "CSV", "XLSX", "PDF"];
|
|
44
|
+
const SHARED_REPORT_VIEW_EXPORT_TYPES = ["JSON_V1", "JSON", "CSV"];
|
|
43
45
|
const SUMMARY_GROUPS = [
|
|
44
46
|
"CLIENT",
|
|
45
47
|
"PROJECT",
|
|
@@ -57,8 +59,9 @@ const nonEmptyStringSchema = z
|
|
|
57
59
|
const dateStringSchema = nonEmptyStringSchema.refine((value) => !Number.isNaN(Date.parse(value)), "must be a valid date string.");
|
|
58
60
|
const upperCaseString = (value) => typeof value === "string" ? value.toUpperCase() : value;
|
|
59
61
|
const sharedReportTypeSchema = z.preprocess(upperCaseString, z.enum(SHARED_REPORT_TYPES));
|
|
60
|
-
const sharedReportExportTypeSchema = z.preprocess(upperCaseString, z.enum(
|
|
61
|
-
const openObjectSchema = z.record(z.unknown());
|
|
62
|
+
const sharedReportExportTypeSchema = z.preprocess(upperCaseString, z.enum(SHARED_REPORT_FILTER_EXPORT_TYPES));
|
|
63
|
+
const openObjectSchema = z.record(z.string(), z.unknown());
|
|
64
|
+
const INT_MESSAGE = { error: "provide a whole integer" };
|
|
62
65
|
const sharedUsersFilterSchema = z
|
|
63
66
|
.object({
|
|
64
67
|
contains: z.enum(["CONTAINS", "DOES_NOT_CONTAIN", "CONTAINS_ONLY"]).optional(),
|
|
@@ -68,8 +71,8 @@ const sharedUsersFilterSchema = z
|
|
|
68
71
|
.strict();
|
|
69
72
|
const sharedAttendanceFilterSchema = z
|
|
70
73
|
.object({
|
|
71
|
-
page: z.number().finite().int().optional(),
|
|
72
|
-
pageSize: z.number().finite().int().optional(),
|
|
74
|
+
page: z.number().finite().int(INT_MESSAGE).optional(),
|
|
75
|
+
pageSize: z.number().finite().int(INT_MESSAGE).optional(),
|
|
73
76
|
users: sharedUsersFilterSchema.optional(),
|
|
74
77
|
})
|
|
75
78
|
.strict();
|
|
@@ -77,15 +80,18 @@ const sharedDetailedFilterSchema = z
|
|
|
77
80
|
.object({
|
|
78
81
|
auditFilter: openObjectSchema.optional(),
|
|
79
82
|
options: openObjectSchema.optional(),
|
|
80
|
-
page: z.number().finite().int().optional(),
|
|
81
|
-
pageSize: z.number().finite().int().optional(),
|
|
83
|
+
page: z.number().finite().int(INT_MESSAGE).optional(),
|
|
84
|
+
pageSize: z.number().finite().int(INT_MESSAGE).optional(),
|
|
82
85
|
sortColumn: nonEmptyStringSchema.optional(),
|
|
83
86
|
sortOrder: z.enum(["ASCENDING", "DESCENDING"]).optional(),
|
|
84
87
|
})
|
|
85
88
|
.strict();
|
|
86
89
|
const sharedSummaryFilterSchema = z
|
|
87
90
|
.object({
|
|
88
|
-
groups: z
|
|
91
|
+
groups: z
|
|
92
|
+
.array(z.enum(SUMMARY_GROUPS))
|
|
93
|
+
.min(1, { error: `provide 1-3 of: ${SUMMARY_GROUPS.join(", ")}` })
|
|
94
|
+
.max(3, { error: `provide at most 3 of: ${SUMMARY_GROUPS.join(", ")}` }),
|
|
89
95
|
sortColumn: nonEmptyStringSchema.optional(),
|
|
90
96
|
})
|
|
91
97
|
.strict();
|
|
@@ -209,9 +215,9 @@ function schemaIssueLabel(issue, operation) {
|
|
|
209
215
|
return operation;
|
|
210
216
|
}
|
|
211
217
|
function sharedReportValidationError(error, operation, rawType) {
|
|
212
|
-
const invalidTypeIssue = error.issues.find((issue) => issue.path[0] === "type" && issue.code === z.ZodIssueCode.
|
|
218
|
+
const invalidTypeIssue = error.issues.find((issue) => issue.path[0] === "type" && issue.code === z.ZodIssueCode.invalid_value);
|
|
213
219
|
if (invalidTypeIssue !== undefined) {
|
|
214
|
-
return new Error(`Unknown --type "${String(rawType)}".
|
|
220
|
+
return new Error(`Unknown --type "${String(rawType)}". Provide one of: ${SHARED_REPORT_TYPES.join(", ")}.`);
|
|
215
221
|
}
|
|
216
222
|
const issue = error.issues[0];
|
|
217
223
|
if (issue === undefined)
|
|
@@ -234,7 +240,7 @@ function parseSharedReportBody(schema, opts, operation) {
|
|
|
234
240
|
name: opts.name,
|
|
235
241
|
type: opts.type,
|
|
236
242
|
filter: parseFilterJson(opts.filter),
|
|
237
|
-
...(opts.public
|
|
243
|
+
...(opts.public !== undefined ? { isPublic: opts.public } : {}),
|
|
238
244
|
};
|
|
239
245
|
const result = schema.safeParse(candidate);
|
|
240
246
|
if (!result.success) {
|
|
@@ -250,16 +256,30 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
250
256
|
.description("List the workspace's shared (public-link) reports.")
|
|
251
257
|
.action(async function () {
|
|
252
258
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
253
|
-
const
|
|
254
|
-
|
|
259
|
+
const response = await client.sharedReports.list({ workspaceId });
|
|
260
|
+
const rows = (response.reports ?? []).map((report) => ({
|
|
261
|
+
id: report.id ?? "",
|
|
262
|
+
name: report.name ?? "",
|
|
263
|
+
type: report.type ?? "",
|
|
264
|
+
isPublic: report.isPublic === true,
|
|
265
|
+
link: report.link ?? "",
|
|
266
|
+
}));
|
|
267
|
+
printRecords(rows, output);
|
|
255
268
|
});
|
|
256
269
|
leafCommand(shared, "view", "read")
|
|
257
270
|
.argument("<id>", "Shared-report ID.")
|
|
258
|
-
.option("--export-type <type>", "
|
|
271
|
+
.option("--export-type <type>", "Text-safe export type: JSON_V1, JSON, or CSV (default JSON_V1).")
|
|
259
272
|
.description("View a shared report's rendered data by ID (reports host; not workspace-scoped).")
|
|
260
273
|
.action(async function (id, opts) {
|
|
261
|
-
const
|
|
262
|
-
|
|
274
|
+
const candidate = opts.exportType ? String(opts.exportType).toUpperCase() : "JSON_V1";
|
|
275
|
+
if (candidate === "XLSX" || candidate === "PDF") {
|
|
276
|
+
throw new Error(`--export-type ${candidate} is unavailable because the CLI cannot stream binary output to a file yet. Provide one of: ${SHARED_REPORT_VIEW_EXPORT_TYPES.join(", ")}. Run \`clk115 shared-reports list\` and open the report link for binary downloads.`);
|
|
277
|
+
}
|
|
278
|
+
if (!SHARED_REPORT_VIEW_EXPORT_TYPES.includes(candidate)) {
|
|
279
|
+
throw new Error(`Unknown --export-type "${String(opts.exportType)}". Provide one of: ${SHARED_REPORT_VIEW_EXPORT_TYPES.join(", ")}.`);
|
|
280
|
+
}
|
|
281
|
+
const { client, output } = await resolveBaseContext(this, services);
|
|
282
|
+
const exportType = candidate;
|
|
263
283
|
const response = await client.sharedReports.view({
|
|
264
284
|
sharedReportId: id,
|
|
265
285
|
exportType,
|
|
@@ -271,6 +291,7 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
271
291
|
.requiredOption("--type <type>", `Report type: ${SHARED_REPORT_TYPES.join(", ")}.`)
|
|
272
292
|
.requiredOption("--filter <json>", "Report filter object as a JSON string.")
|
|
273
293
|
.option("--public", "Make the report publicly accessible.")
|
|
294
|
+
.option("--no-public", "Make the report private (no public link).")
|
|
274
295
|
.description("Create a shared (public-link) report.")
|
|
275
296
|
.action(async function (opts) {
|
|
276
297
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
@@ -299,6 +320,7 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
299
320
|
.requiredOption("--type <type>", `Report type: ${SHARED_REPORT_TYPES.join(", ")}.`)
|
|
300
321
|
.requiredOption("--filter <json>", "Report filter object as a JSON string (full replace).")
|
|
301
322
|
.option("--public", "Make the report publicly accessible.")
|
|
323
|
+
.option("--no-public", "Make the report private (no public link).")
|
|
302
324
|
.description("Replace a shared report by ID (full replace of name, type, and filter).")
|
|
303
325
|
.action(async function (id, opts) {
|
|
304
326
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
package/dist/commands/start.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { entityId } from "clockify-sdk-ts-115/operation-receipt";
|
|
2
1
|
import { printReceipt } from "../receipt.js";
|
|
3
2
|
import { resolveContext } from "./helpers.js";
|
|
4
3
|
import { leafCommand } from "./leaf-command.js";
|
|
@@ -13,11 +12,6 @@ export const registerStartCommand = (program, services) => {
|
|
|
13
12
|
.option("--billable", "Mark the entry as billable.", false)
|
|
14
13
|
.action(async function (description, opts) {
|
|
15
14
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
16
|
-
const user = await client.users.getCurrentUser();
|
|
17
|
-
const userId = entityId(user);
|
|
18
|
-
if (!userId) {
|
|
19
|
-
throw new Error("could not determine user ID from getCurrentUser response");
|
|
20
|
-
}
|
|
21
15
|
const projectId = opts.project
|
|
22
16
|
? await resolveProjectId(client, workspaceId, opts.project)
|
|
23
17
|
: undefined;
|
package/dist/commands/stop.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { entityId } from "clockify-sdk-ts-115/operation-receipt";
|
|
2
|
-
import { printSuccess } from "../output.js";
|
|
3
2
|
import { printReceipt } from "../receipt.js";
|
|
4
3
|
import { resolveContext } from "./helpers.js";
|
|
5
4
|
import { leafCommand } from "./leaf-command.js";
|
|
@@ -16,7 +15,15 @@ export const registerStopCommand = (program, services) => {
|
|
|
16
15
|
const inProgress = (await client.timeEntries.listInProgress({ workspaceId }));
|
|
17
16
|
const running = inProgress.find((entry) => entry.userId === userId && entry.id);
|
|
18
17
|
if (!running) {
|
|
19
|
-
|
|
18
|
+
printReceipt({
|
|
19
|
+
ok: true,
|
|
20
|
+
action: "timer.stop",
|
|
21
|
+
entity: "time_entry",
|
|
22
|
+
ids: {},
|
|
23
|
+
data: { message: "no timer was running" },
|
|
24
|
+
changed: {},
|
|
25
|
+
next: [{ command: "clk115 start --json", reason: "Start a timer." }],
|
|
26
|
+
}, output);
|
|
20
27
|
return;
|
|
21
28
|
}
|
|
22
29
|
const end = new Date().toISOString();
|
package/dist/commands/tags.js
CHANGED
|
@@ -67,6 +67,9 @@ export const registerTagsCommand = (program, services) => {
|
|
|
67
67
|
.option("--no-archived", "Unarchive the tag.")
|
|
68
68
|
.description("Update a tag by ID.")
|
|
69
69
|
.action(async function (id, opts) {
|
|
70
|
+
if (!opts.name && opts.archived === undefined) {
|
|
71
|
+
throw new Error("tags.update needs a change: provide at least one tag field.");
|
|
72
|
+
}
|
|
70
73
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
71
74
|
const body = {};
|
|
72
75
|
if (opts.name)
|
package/dist/commands/tasks.js
CHANGED
|
@@ -11,7 +11,7 @@ function requireTaskName(value, source) {
|
|
|
11
11
|
function taskStatus(value, source) {
|
|
12
12
|
const status = String(value).toUpperCase();
|
|
13
13
|
if (status !== "ACTIVE" && status !== "DONE") {
|
|
14
|
-
throw new Error(`${source} has unknown task status: ${String(value)}`);
|
|
14
|
+
throw new Error(`${source} has unknown task status: ${String(value)}; provide ACTIVE or DONE`);
|
|
15
15
|
}
|
|
16
16
|
return status;
|
|
17
17
|
}
|
|
@@ -177,7 +177,7 @@ export const registerTasksCommand = (program, services) => {
|
|
|
177
177
|
opts.billable !== undefined ||
|
|
178
178
|
opts.assignee !== undefined;
|
|
179
179
|
if (!hasChanges) {
|
|
180
|
-
throw new Error("tasks.update
|
|
180
|
+
throw new Error("tasks.update needs a change: provide at least one task field.");
|
|
181
181
|
}
|
|
182
182
|
const current = (await client.tasks.get({
|
|
183
183
|
workspaceId,
|
|
@@ -204,7 +204,7 @@ export const registerTasksCommand = (program, services) => {
|
|
|
204
204
|
body.assigneeIds = opts.assignee;
|
|
205
205
|
}
|
|
206
206
|
if (!changed) {
|
|
207
|
-
throw new Error("tasks.update values are unchanged;
|
|
207
|
+
throw new Error("tasks.update values are unchanged; provide a different value.");
|
|
208
208
|
}
|
|
209
209
|
const req = {
|
|
210
210
|
workspaceId,
|
|
@@ -265,7 +265,11 @@ export const registerTasksCommand = (program, services) => {
|
|
|
265
265
|
taskId: id,
|
|
266
266
|
body: originalBody,
|
|
267
267
|
};
|
|
268
|
-
|
|
268
|
+
try {
|
|
269
|
+
await client.tasks.update(rollbackRequest);
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
}
|
|
269
273
|
}
|
|
270
274
|
throw error;
|
|
271
275
|
}
|
package/dist/commands/timeoff.js
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { printRecords } from "../output.js";
|
|
2
2
|
import { printReceipt } from "../receipt.js";
|
|
3
|
+
import { registerBalanceAssignmentCommands } from "./balanceAssignment.js";
|
|
3
4
|
import { clampPageSize, parseIntArg, resolveContext, splitList } from "./helpers.js";
|
|
4
5
|
import { leafCommand } from "./leaf-command.js";
|
|
5
6
|
export const registerTimeOffCommand = (program, services) => {
|
|
6
7
|
const timeoff = program.command("timeoff").description("Time-off requests.");
|
|
8
|
+
registerBalanceAssignmentCommands(timeoff, services);
|
|
7
9
|
leafCommand(timeoff, "list", "read")
|
|
8
10
|
.description("List time-off requests in the workspace.")
|
|
9
11
|
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
10
12
|
.option("--limit <n>", "Items per page (default 50, max 200).", parseIntArg, 50)
|
|
11
13
|
.option("--start <date>", "Window start (YYYY-MM-DD or RFC3339).")
|
|
12
14
|
.option("--end <date>", "Window end (YYYY-MM-DD or RFC3339).")
|
|
13
|
-
.option("--status <statuses>", "Comma-separated statuses (
|
|
15
|
+
.option("--status <statuses>", "Comma-separated statuses (PENDING, APPROVED, REJECTED, ALL).")
|
|
14
16
|
.option("--user <ids>", "Comma-separated user IDs to scope the search.")
|
|
15
17
|
.action(async function (opts) {
|
|
16
18
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
@@ -24,16 +26,17 @@ export const registerTimeOffCommand = (program, services) => {
|
|
|
24
26
|
if (opts.end)
|
|
25
27
|
req.end = opts.end;
|
|
26
28
|
if (opts.status) {
|
|
27
|
-
const statuses = splitList(opts.status);
|
|
29
|
+
const statuses = splitList(opts.status).map((s) => s.toUpperCase());
|
|
28
30
|
const known = new Set(["PENDING", "APPROVED", "REJECTED", "ALL"]);
|
|
29
31
|
const invalid = statuses.filter((status) => !known.has(status));
|
|
30
32
|
if (invalid.length > 0)
|
|
31
|
-
throw new Error(`Unknown time-off status: ${invalid.join(", ")}`);
|
|
33
|
+
throw new Error(`Unknown time-off status: ${invalid.join(", ")}; provide PENDING, APPROVED, REJECTED, or ALL`);
|
|
32
34
|
req.statuses = statuses;
|
|
33
35
|
}
|
|
34
36
|
if (opts.user)
|
|
35
37
|
req.users = splitList(opts.user);
|
|
36
|
-
const
|
|
38
|
+
const response = await client.timeOff.list(req);
|
|
39
|
+
const items = response.requests ?? [];
|
|
37
40
|
const rows = items.map((raw) => {
|
|
38
41
|
const r = raw;
|
|
39
42
|
const statusValue = typeof r.status === "object" && r.status !== null
|
|
@@ -66,6 +69,10 @@ export const registerTimeOffCommand = (program, services) => {
|
|
|
66
69
|
if (opts.end === undefined && !Number.isFinite(opts.days)) {
|
|
67
70
|
throw new Error("provide --end (date-range / HOURS-unit policies) or --days (DAYS-unit policies)");
|
|
68
71
|
}
|
|
72
|
+
const halfDayPeriod = opts.halfDayPeriod === undefined ? "NOT_DEFINED" : String(opts.halfDayPeriod).toUpperCase();
|
|
73
|
+
if (!["FIRST_HALF", "SECOND_HALF", "NOT_DEFINED"].includes(halfDayPeriod)) {
|
|
74
|
+
throw new Error(`--half-day-period must be FIRST_HALF, SECOND_HALF, or NOT_DEFINED (got "${String(opts.halfDayPeriod)}").`);
|
|
75
|
+
}
|
|
69
76
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
70
77
|
const period = { start: opts.start };
|
|
71
78
|
if (opts.end !== undefined)
|
|
@@ -76,7 +83,7 @@ export const registerTimeOffCommand = (program, services) => {
|
|
|
76
83
|
note: opts.note ?? "",
|
|
77
84
|
timeOffPeriod: {
|
|
78
85
|
isHalfDay: opts.halfDay === true,
|
|
79
|
-
halfDayPeriod:
|
|
86
|
+
halfDayPeriod: halfDayPeriod,
|
|
80
87
|
period,
|
|
81
88
|
},
|
|
82
89
|
};
|