@apet97/clockify-cli-115 5.0.3 → 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.
- package/README.md +96 -26
- package/dist/client.js +18 -15
- package/dist/closed-pipe.js +3 -0
- package/dist/commands/api.js +182 -61
- package/dist/commands/approvals.js +9 -7
- package/dist/commands/auditlog.js +11 -8
- package/dist/commands/balanceAssignment.js +10 -8
- package/dist/commands/clients.js +16 -7
- package/dist/commands/doctor.js +42 -25
- package/dist/commands/entries.js +29 -14
- package/dist/commands/expenses.js +64 -22
- package/dist/commands/helpers.js +28 -7
- package/dist/commands/invoices.js +12 -16
- package/dist/commands/leaf-command.js +8 -0
- package/dist/commands/log.js +4 -2
- package/dist/commands/projects.js +18 -9
- package/dist/commands/reports.js +73 -23
- package/dist/commands/resolve-refs.js +30 -53
- package/dist/commands/scheduling.js +94 -40
- package/dist/commands/shared-report-body.js +205 -0
- package/dist/commands/sharedReports.js +19 -215
- package/dist/commands/start.js +6 -4
- package/dist/commands/status.js +55 -19
- package/dist/commands/stop.js +15 -17
- package/dist/commands/tags.js +6 -4
- package/dist/commands/tasks.js +18 -23
- package/dist/commands/timeoff.js +23 -16
- package/dist/commands/users.js +7 -5
- package/dist/commands/webhooks.js +14 -12
- package/dist/completions.js +290 -55
- package/dist/config.js +10 -6
- package/dist/duration.js +5 -4
- package/dist/error-codes.js +34 -6
- package/dist/failure.js +87 -0
- package/dist/flags.js +74 -0
- package/dist/generated/version.js +1 -1
- package/dist/index.js +41 -105
- package/dist/output.js +62 -28
- package/dist/write-outcome.js +84 -0
- package/package.json +3 -3
package/dist/commands/helpers.js
CHANGED
|
@@ -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 {
|
|
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
|
|
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
|
|
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
|
|
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 {
|
|
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 ??
|
|
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>",
|
|
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
|
-
|
|
61
|
-
|
|
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()}`);
|
package/dist/commands/log.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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
|
});
|
package/dist/commands/reports.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { REPORT_PERIODS, resolveInstant, resolvePeriod, } from "clockify-sdk-ts-115/dates";
|
|
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,36 +12,69 @@ function resolveRange(opts) {
|
|
|
11
12
|
.toLowerCase()
|
|
12
13
|
.replace(/[\s-]+/g, "_");
|
|
13
14
|
if (!REPORT_PERIODS.includes(periodInput)) {
|
|
14
|
-
throw new
|
|
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
|
|
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
|
|
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 };
|
|
31
32
|
}
|
|
32
|
-
function
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
function resolveWeeklyRange(opts) {
|
|
34
|
+
const parsedFrom = inspectWeeklyInput(opts.from, "--from");
|
|
35
|
+
const parsedTo = inspectWeeklyInput(opts.to, "--to");
|
|
36
|
+
const resolved = resolveRange(opts);
|
|
37
|
+
const dateRangeStart = parsedFrom === undefined
|
|
38
|
+
? resolved.dateRangeStart
|
|
39
|
+
: parsedFrom.dateOnly
|
|
40
|
+
? `${parsedFrom.raw}T00:00:00.000Z`
|
|
41
|
+
: parsedFrom.raw;
|
|
42
|
+
let dateRangeEnd = parsedTo === undefined ? resolved.dateRangeEnd : parsedTo.raw;
|
|
43
|
+
if (parsedTo?.dateOnly === true) {
|
|
44
|
+
const exclusive = `${parsedTo.raw}T00:00:00.000Z`;
|
|
45
|
+
const inclusive = `${parsedTo.raw}T23:59:59.999Z`;
|
|
46
|
+
dateRangeEnd = isExactWeeklyRange(dateRangeStart, exclusive) ? exclusive : inclusive;
|
|
37
47
|
}
|
|
38
|
-
|
|
39
|
-
|
|
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.");
|
|
48
|
+
if (!isExactWeeklyRange(dateRangeStart, dateRangeEnd)) {
|
|
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.");
|
|
43
50
|
}
|
|
51
|
+
return { dateRangeStart, dateRangeEnd };
|
|
52
|
+
}
|
|
53
|
+
function inspectWeeklyInput(raw, option) {
|
|
54
|
+
if (raw === undefined)
|
|
55
|
+
return undefined;
|
|
56
|
+
const trimmed = raw.trim();
|
|
57
|
+
if (trimmed.length === 0) {
|
|
58
|
+
throw new UsageError(`${option} must not be empty; provide YYYY-MM-DD, a full-seconds weekly timestamp, or a period name.`);
|
|
59
|
+
}
|
|
60
|
+
if (isDateOnly(trimmed)) {
|
|
61
|
+
if (parseWeeklyDateTime(`${trimmed}T00:00:00`) === undefined) {
|
|
62
|
+
throw invalidWeeklyInput(option, raw);
|
|
63
|
+
}
|
|
64
|
+
return { raw: trimmed, dateOnly: true };
|
|
65
|
+
}
|
|
66
|
+
if (!/^\d{4}-\d{2}-\d{2}/u.test(trimmed))
|
|
67
|
+
return undefined;
|
|
68
|
+
const parsed = parseWeeklyDateTime(trimmed);
|
|
69
|
+
if (parsed !== undefined)
|
|
70
|
+
return { raw: trimmed, dateOnly: false };
|
|
71
|
+
throw invalidWeeklyInput(option, raw);
|
|
72
|
+
}
|
|
73
|
+
function isDateOnly(value) {
|
|
74
|
+
return /^\d{4}-\d{2}-\d{2}$/u.test(value);
|
|
75
|
+
}
|
|
76
|
+
function invalidWeeklyInput(option, raw) {
|
|
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].`);
|
|
44
78
|
}
|
|
45
79
|
function idFilter(ids) {
|
|
46
80
|
return { ids, contains: "CONTAINS" };
|
|
@@ -62,29 +96,32 @@ function parseSummaryGroups(raw) {
|
|
|
62
96
|
.map((group) => group.trim().toUpperCase())
|
|
63
97
|
.filter(Boolean);
|
|
64
98
|
if (groups.length === 0 || groups.length > 3) {
|
|
65
|
-
throw new
|
|
99
|
+
throw new UsageError(`--groups must contain between one and three summary groups; provide 1-3 of: ${SUMMARY_GROUPS.join(", ")}.`);
|
|
66
100
|
}
|
|
67
101
|
const unknown = groups.find((group) => !SUMMARY_GROUPS.includes(group));
|
|
68
102
|
if (unknown) {
|
|
69
|
-
throw new
|
|
103
|
+
throw new UsageError(`Unknown summary group: ${unknown}. Provide one of: ${SUMMARY_GROUPS.join(", ")}.`);
|
|
70
104
|
}
|
|
71
105
|
return groups;
|
|
72
106
|
}
|
|
73
107
|
function parseWeeklyGroup(raw) {
|
|
74
108
|
const group = String(raw).toUpperCase();
|
|
75
109
|
if (group !== "USER" && group !== "PROJECT") {
|
|
76
|
-
throw new
|
|
110
|
+
throw new UsageError("Unknown --group for the weekly report. Provide one of: USER, PROJECT.");
|
|
77
111
|
}
|
|
78
112
|
return group;
|
|
79
113
|
}
|
|
80
114
|
function parseWeeklySubgroup(raw) {
|
|
81
115
|
const subgroup = String(raw).toUpperCase();
|
|
82
116
|
if (subgroup !== "TIME") {
|
|
83
|
-
throw new
|
|
117
|
+
throw new UsageError("Unknown --subgroup for the weekly report. Provide one of: TIME.");
|
|
84
118
|
}
|
|
85
119
|
return subgroup;
|
|
86
120
|
}
|
|
87
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
|
+
}
|
|
88
125
|
export const registerReportsCommand = (program, services) => {
|
|
89
126
|
const reports = program.command("reports").description("Run Clockify reports (read-only).");
|
|
90
127
|
leafCommand(reports, "summary", "read")
|
|
@@ -99,16 +136,20 @@ export const registerReportsCommand = (program, services) => {
|
|
|
99
136
|
.option("--billable", "Only billable time.", false)
|
|
100
137
|
.option("--project <name|id...>", "Scope to one or more project names or ids.")
|
|
101
138
|
.option("--client <name|id...>", "Scope to one or more client names or ids.")
|
|
139
|
+
.option("--time-view-mode <mode>", TIME_VIEW_MODE_HELP)
|
|
102
140
|
.action(async function (opts) {
|
|
103
|
-
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
104
141
|
const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
|
|
105
142
|
const groups = parseSummaryGroups(opts.groups);
|
|
143
|
+
const timeViewMode = optionalTimeViewMode(opts);
|
|
144
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
106
145
|
const req = {
|
|
107
146
|
workspaceId,
|
|
108
147
|
dateRangeStart,
|
|
109
148
|
dateRangeEnd,
|
|
110
149
|
summaryFilter: summaryFilter(groups),
|
|
111
150
|
};
|
|
151
|
+
if (timeViewMode !== undefined)
|
|
152
|
+
req.timeViewMode = timeViewMode;
|
|
112
153
|
if (opts.billable)
|
|
113
154
|
req.billable = true;
|
|
114
155
|
if (Array.isArray(opts.project) && opts.project.length > 0) {
|
|
@@ -130,7 +171,9 @@ export const registerReportsCommand = (program, services) => {
|
|
|
130
171
|
.option("--to <date>", "Range end; overrides --period.")
|
|
131
172
|
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
132
173
|
.option("--page-size <n>", "Entries per page (max 1000).", parseIntArg, 50)
|
|
174
|
+
.option("--time-view-mode <mode>", TIME_VIEW_MODE_HELP)
|
|
133
175
|
.action(async function (opts) {
|
|
176
|
+
const timeViewMode = optionalTimeViewMode(opts);
|
|
134
177
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
135
178
|
const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
|
|
136
179
|
const req = {
|
|
@@ -141,6 +184,7 @@ export const registerReportsCommand = (program, services) => {
|
|
|
141
184
|
page: opts.page,
|
|
142
185
|
pageSize: clampPageSize(opts.pageSize, 1000),
|
|
143
186
|
}),
|
|
187
|
+
...(timeViewMode !== undefined ? { timeViewMode } : {}),
|
|
144
188
|
};
|
|
145
189
|
const data = await client.reports.detailed(req);
|
|
146
190
|
printObject(data, output);
|
|
@@ -153,15 +197,18 @@ export const registerReportsCommand = (program, services) => {
|
|
|
153
197
|
.option("--to <date>", "Range end; overrides --period.")
|
|
154
198
|
.option("--group <group>", "Top grouping: USER or PROJECT.", "USER")
|
|
155
199
|
.option("--subgroup <subgroup>", "Subgrouping (TIME).", "TIME")
|
|
200
|
+
.option("--time-view-mode <mode>", TIME_VIEW_MODE_HELP)
|
|
156
201
|
.action(async function (opts) {
|
|
202
|
+
const { dateRangeStart, dateRangeEnd } = resolveWeeklyRange(opts);
|
|
203
|
+
const timeViewMode = optionalTimeViewMode(opts);
|
|
204
|
+
const filter = weeklyFilter(parseWeeklyGroup(opts.group), parseWeeklySubgroup(opts.subgroup));
|
|
157
205
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
158
|
-
const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
|
|
159
|
-
assertWeeklyRange(dateRangeStart, dateRangeEnd);
|
|
160
206
|
const req = {
|
|
161
207
|
workspaceId,
|
|
162
208
|
dateRangeStart,
|
|
163
209
|
dateRangeEnd,
|
|
164
|
-
weeklyFilter:
|
|
210
|
+
weeklyFilter: filter,
|
|
211
|
+
...(timeViewMode !== undefined ? { timeViewMode } : {}),
|
|
165
212
|
};
|
|
166
213
|
const data = await client.reports.weekly(req);
|
|
167
214
|
printObject(data, output);
|
|
@@ -172,7 +219,9 @@ export const registerReportsCommand = (program, services) => {
|
|
|
172
219
|
.option("--period <p>", PERIOD_HELP)
|
|
173
220
|
.option("--from <date>", "Range start; overrides --period.")
|
|
174
221
|
.option("--to <date>", "Range end; overrides --period.")
|
|
222
|
+
.option("--time-view-mode <mode>", TIME_VIEW_MODE_HELP)
|
|
175
223
|
.action(async function (opts) {
|
|
224
|
+
const timeViewMode = optionalTimeViewMode(opts);
|
|
176
225
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
177
226
|
const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
|
|
178
227
|
const req = {
|
|
@@ -180,6 +229,7 @@ export const registerReportsCommand = (program, services) => {
|
|
|
180
229
|
dateRangeStart,
|
|
181
230
|
dateRangeEnd,
|
|
182
231
|
attendanceFilter: {},
|
|
232
|
+
...(timeViewMode !== undefined ? { timeViewMode } : {}),
|
|
183
233
|
};
|
|
184
234
|
const data = await client.reports.attendance(req);
|
|
185
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|