@apet97/clockify-cli-115 0.1.0 → 0.3.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 +9 -5
- package/dist/commands/api.js +2 -2
- package/dist/commands/auditlog.js +10 -4
- package/dist/commands/clients.js +82 -22
- package/dist/commands/doctor.js +7 -11
- package/dist/commands/entries.js +3 -4
- package/dist/commands/expenses.js +22 -17
- package/dist/commands/invoices.js +3 -4
- package/dist/commands/leaf-command.js +45 -0
- package/dist/commands/log.js +5 -4
- package/dist/commands/projects.js +7 -11
- package/dist/commands/reports.js +45 -13
- package/dist/commands/scheduling.js +3 -4
- package/dist/commands/sharedReports.js +214 -39
- package/dist/commands/start.js +2 -2
- package/dist/commands/status.js +27 -3
- package/dist/commands/stop.js +2 -2
- package/dist/commands/tags.js +7 -6
- package/dist/commands/tasks.js +156 -32
- package/dist/commands/timeoff.js +12 -8
- package/dist/commands/users.js +5 -8
- package/dist/commands/webhooks.js +131 -24
- package/dist/config.js +5 -4
- package/dist/error-codes.js +2 -1
- package/dist/generated/version.js +1 -0
- package/dist/index.js +11 -13
- package/dist/output.js +2 -2
- package/package.json +12 -11
package/dist/commands/reports.js
CHANGED
|
@@ -2,6 +2,7 @@ import { REPORT_PERIODS, resolveInstant, resolvePeriod, } from "clockify-sdk-ts-
|
|
|
2
2
|
import { detailedFilter, summaryFilter, weeklyFilter } from "clockify-sdk-ts-115/reports";
|
|
3
3
|
import { printObject } from "../output.js";
|
|
4
4
|
import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
|
|
5
|
+
import { leafCommand } from "./leaf-command.js";
|
|
5
6
|
import { resolveClientId, resolveProjectId } from "./resolve-refs.js";
|
|
6
7
|
function resolveRange(opts) {
|
|
7
8
|
const now = new Date();
|
|
@@ -31,11 +32,48 @@ function resolveRange(opts) {
|
|
|
31
32
|
function idFilter(ids) {
|
|
32
33
|
return { ids, contains: "CONTAINS" };
|
|
33
34
|
}
|
|
35
|
+
const SUMMARY_GROUPS = [
|
|
36
|
+
"CLIENT",
|
|
37
|
+
"PROJECT",
|
|
38
|
+
"USER",
|
|
39
|
+
"WEEK",
|
|
40
|
+
"DATE",
|
|
41
|
+
"MONTH",
|
|
42
|
+
"TIMEENTRY",
|
|
43
|
+
"TASK",
|
|
44
|
+
];
|
|
45
|
+
function parseSummaryGroups(raw) {
|
|
46
|
+
const groups = String(raw)
|
|
47
|
+
.split(",")
|
|
48
|
+
.map((group) => group.trim().toUpperCase())
|
|
49
|
+
.filter(Boolean);
|
|
50
|
+
if (groups.length === 0 || groups.length > 3) {
|
|
51
|
+
throw new Error("--groups must contain between one and three summary groups.");
|
|
52
|
+
}
|
|
53
|
+
const unknown = groups.find((group) => !SUMMARY_GROUPS.includes(group));
|
|
54
|
+
if (unknown) {
|
|
55
|
+
throw new Error(`Unknown summary group: ${unknown}. Use one of: ${SUMMARY_GROUPS.join(", ")}.`);
|
|
56
|
+
}
|
|
57
|
+
return groups;
|
|
58
|
+
}
|
|
59
|
+
function parseWeeklyGroup(raw) {
|
|
60
|
+
const group = String(raw).toUpperCase();
|
|
61
|
+
if (group !== "USER" && group !== "PROJECT") {
|
|
62
|
+
throw new Error("Weekly group must be USER or PROJECT.");
|
|
63
|
+
}
|
|
64
|
+
return group;
|
|
65
|
+
}
|
|
66
|
+
function parseWeeklySubgroup(raw) {
|
|
67
|
+
const subgroup = String(raw).toUpperCase();
|
|
68
|
+
if (subgroup !== "TIME") {
|
|
69
|
+
throw new Error("Weekly subgroup must be TIME.");
|
|
70
|
+
}
|
|
71
|
+
return subgroup;
|
|
72
|
+
}
|
|
34
73
|
const PERIOD_HELP = `Named period: ${REPORT_PERIODS.join(", ")} (default this_month).`;
|
|
35
74
|
export const registerReportsCommand = (program, services) => {
|
|
36
75
|
const reports = program.command("reports").description("Run Clockify reports (read-only).");
|
|
37
|
-
reports
|
|
38
|
-
.command("summary")
|
|
76
|
+
leafCommand(reports, "summary", "read")
|
|
39
77
|
.description("Summary report totals over a date range, grouped per --groups.")
|
|
40
78
|
.option("--period <p>", PERIOD_HELP)
|
|
41
79
|
.option("--from <date>", "Range start (YYYY-MM-DD, ISO, or a period); overrides --period.")
|
|
@@ -47,10 +85,7 @@ export const registerReportsCommand = (program, services) => {
|
|
|
47
85
|
.action(async function (opts) {
|
|
48
86
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
49
87
|
const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
|
|
50
|
-
const groups =
|
|
51
|
-
.split(",")
|
|
52
|
-
.map((g) => g.trim().toUpperCase())
|
|
53
|
-
.filter(Boolean);
|
|
88
|
+
const groups = parseSummaryGroups(opts.groups);
|
|
54
89
|
const req = {
|
|
55
90
|
workspaceId,
|
|
56
91
|
dateRangeStart,
|
|
@@ -70,8 +105,7 @@ export const registerReportsCommand = (program, services) => {
|
|
|
70
105
|
const data = await client.reports.summary(req);
|
|
71
106
|
printObject(data, output);
|
|
72
107
|
});
|
|
73
|
-
reports
|
|
74
|
-
.command("detailed")
|
|
108
|
+
leafCommand(reports, "detailed", "read")
|
|
75
109
|
.description("Detailed report listing individual time entries over a date range.")
|
|
76
110
|
.option("--period <p>", PERIOD_HELP)
|
|
77
111
|
.option("--from <date>", "Range start; overrides --period.")
|
|
@@ -93,8 +127,7 @@ export const registerReportsCommand = (program, services) => {
|
|
|
93
127
|
const data = await client.reports.detailed(req);
|
|
94
128
|
printObject(data, output);
|
|
95
129
|
});
|
|
96
|
-
reports
|
|
97
|
-
.command("weekly")
|
|
130
|
+
leafCommand(reports, "weekly", "read")
|
|
98
131
|
.description("Weekly report aggregating tracked time per week over a date range.")
|
|
99
132
|
.option("--period <p>", PERIOD_HELP)
|
|
100
133
|
.option("--from <date>", "Range start; overrides --period.")
|
|
@@ -108,13 +141,12 @@ export const registerReportsCommand = (program, services) => {
|
|
|
108
141
|
workspaceId,
|
|
109
142
|
dateRangeStart,
|
|
110
143
|
dateRangeEnd,
|
|
111
|
-
weeklyFilter: weeklyFilter(
|
|
144
|
+
weeklyFilter: weeklyFilter(parseWeeklyGroup(opts.group), parseWeeklySubgroup(opts.subgroup)),
|
|
112
145
|
};
|
|
113
146
|
const data = await client.reports.weekly(req);
|
|
114
147
|
printObject(data, output);
|
|
115
148
|
});
|
|
116
|
-
reports
|
|
117
|
-
.command("attendance")
|
|
149
|
+
leafCommand(reports, "attendance", "read")
|
|
118
150
|
.description("Attendance report of clock-in/out activity over a date range.")
|
|
119
151
|
.option("--period <p>", PERIOD_HELP)
|
|
120
152
|
.option("--from <date>", "Range start; overrides --period.")
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { printRecords } from "../output.js";
|
|
2
2
|
import { printReceipt } from "../receipt.js";
|
|
3
3
|
import { clampPageSize, parseFloatArg, parseIntArg, promoteDateBoundary, resolveContext, } from "./helpers.js";
|
|
4
|
+
import { leafCommand } from "./leaf-command.js";
|
|
4
5
|
export const registerSchedulingCommand = (program, services) => {
|
|
5
6
|
const scheduling = program
|
|
6
7
|
.command("scheduling")
|
|
7
8
|
.description("Capacity scheduling assignments.");
|
|
8
|
-
scheduling
|
|
9
|
-
.command("list")
|
|
9
|
+
leafCommand(scheduling, "list", "read")
|
|
10
10
|
.description("List scheduling assignments over a date range. --from/--to are required (the endpoint 400s without them).")
|
|
11
11
|
.requiredOption("--from <date>", "Range start (YYYY-MM-DD or RFC3339). Required.")
|
|
12
12
|
.requiredOption("--to <date>", "Range end (YYYY-MM-DD or RFC3339). Required.")
|
|
@@ -41,8 +41,7 @@ export const registerSchedulingCommand = (program, services) => {
|
|
|
41
41
|
});
|
|
42
42
|
printRecords(rows, output);
|
|
43
43
|
});
|
|
44
|
-
scheduling
|
|
45
|
-
.command("create")
|
|
44
|
+
leafCommand(scheduling, "create", "write")
|
|
46
45
|
.description("Create a scheduling assignment (defaults to draft; pass --publish to publish).")
|
|
47
46
|
.requiredOption("--user <id>", "User ID to assign.")
|
|
48
47
|
.requiredOption("--project <id>", "Project ID.")
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from "zod";
|
|
2
2
|
import { printObject } from "../output.js";
|
|
3
3
|
import { printReceipt } from "../receipt.js";
|
|
4
4
|
import { resolveContext } from "./helpers.js";
|
|
5
|
+
import { leafCommand } from "./leaf-command.js";
|
|
5
6
|
async function readReportBody(response) {
|
|
6
7
|
const text = new TextDecoder().decode(await response.arrayBuffer());
|
|
7
8
|
if (!text)
|
|
@@ -23,6 +24,7 @@ const SHARED_REPORT_TYPES = [
|
|
|
23
24
|
"WEEKLY",
|
|
24
25
|
"EXPENSE_DETAILED",
|
|
25
26
|
"INVOICE_TIME",
|
|
27
|
+
"KIOSK_PIN_LIST",
|
|
26
28
|
"ATTENDANCE_DETAILED",
|
|
27
29
|
"ATTENDANCE_SUMMARY",
|
|
28
30
|
"ASSIGNMENT_LIST",
|
|
@@ -30,42 +32,228 @@ const SHARED_REPORT_TYPES = [
|
|
|
30
32
|
"APPROVAL_DETAILED",
|
|
31
33
|
"APPROVAL_SUMMARY",
|
|
32
34
|
"BALANCE_LIST",
|
|
35
|
+
"INVOICE_AMOUNT_LIST",
|
|
36
|
+
"INVOICE_DETAILED",
|
|
33
37
|
"TIMEOFF_DETAILED",
|
|
38
|
+
"TIMEOFF_HOLIDAY",
|
|
39
|
+
"TIMEOFF_BALANCE",
|
|
34
40
|
"EXPENSE_SUMMARY",
|
|
35
41
|
];
|
|
36
|
-
|
|
42
|
+
const SHARED_REPORT_EXPORT_TYPES = ["JSON_V1", "JSON", "CSV", "XLSX", "PDF"];
|
|
43
|
+
const SUMMARY_GROUPS = [
|
|
44
|
+
"CLIENT",
|
|
45
|
+
"PROJECT",
|
|
46
|
+
"TASK",
|
|
47
|
+
"DATE",
|
|
48
|
+
"WEEK",
|
|
49
|
+
"MONTH",
|
|
50
|
+
"TIMEENTRY",
|
|
51
|
+
"USER",
|
|
52
|
+
"TAG",
|
|
53
|
+
];
|
|
54
|
+
const nonEmptyStringSchema = z
|
|
55
|
+
.string()
|
|
56
|
+
.refine((value) => value.trim() !== "", "must be a non-empty string.");
|
|
57
|
+
const dateStringSchema = nonEmptyStringSchema.refine((value) => !Number.isNaN(Date.parse(value)), "must be a valid date string.");
|
|
58
|
+
const upperCaseString = (value) => typeof value === "string" ? value.toUpperCase() : value;
|
|
59
|
+
const sharedReportTypeSchema = z.preprocess(upperCaseString, z.enum(SHARED_REPORT_TYPES));
|
|
60
|
+
const sharedReportExportTypeSchema = z.preprocess(upperCaseString, z.enum(SHARED_REPORT_EXPORT_TYPES));
|
|
61
|
+
const openObjectSchema = z.record(z.unknown());
|
|
62
|
+
const sharedUsersFilterSchema = z
|
|
63
|
+
.object({
|
|
64
|
+
contains: z.enum(["CONTAINS", "DOES_NOT_CONTAIN", "CONTAINS_ONLY"]).optional(),
|
|
65
|
+
ids: z.array(z.string()).optional(),
|
|
66
|
+
status: z.enum(["ALL", "ACTIVE", "INACTIVE"]).optional(),
|
|
67
|
+
})
|
|
68
|
+
.strict();
|
|
69
|
+
const sharedAttendanceFilterSchema = z
|
|
70
|
+
.object({
|
|
71
|
+
page: z.number().finite().int().optional(),
|
|
72
|
+
pageSize: z.number().finite().int().optional(),
|
|
73
|
+
users: sharedUsersFilterSchema.optional(),
|
|
74
|
+
})
|
|
75
|
+
.strict();
|
|
76
|
+
const sharedDetailedFilterSchema = z
|
|
77
|
+
.object({
|
|
78
|
+
auditFilter: openObjectSchema.optional(),
|
|
79
|
+
options: openObjectSchema.optional(),
|
|
80
|
+
page: z.number().finite().int().optional(),
|
|
81
|
+
pageSize: z.number().finite().int().optional(),
|
|
82
|
+
sortColumn: nonEmptyStringSchema.optional(),
|
|
83
|
+
sortOrder: z.enum(["ASCENDING", "DESCENDING"]).optional(),
|
|
84
|
+
})
|
|
85
|
+
.strict();
|
|
86
|
+
const sharedSummaryFilterSchema = z
|
|
87
|
+
.object({
|
|
88
|
+
groups: z.array(z.enum(SUMMARY_GROUPS)).min(1).max(3),
|
|
89
|
+
sortColumn: nonEmptyStringSchema.optional(),
|
|
90
|
+
})
|
|
91
|
+
.strict();
|
|
92
|
+
const sharedWeeklyFilterSchema = z
|
|
93
|
+
.object({
|
|
94
|
+
group: z.enum(["PROJECT", "USER"]),
|
|
95
|
+
subgroup: z.literal("TIME"),
|
|
96
|
+
})
|
|
97
|
+
.strict();
|
|
98
|
+
const sharedReportFilterSchema = z
|
|
99
|
+
.object({
|
|
100
|
+
attendanceFilter: sharedAttendanceFilterSchema.optional(),
|
|
101
|
+
dateRangeEnd: dateStringSchema,
|
|
102
|
+
dateRangeStart: dateStringSchema,
|
|
103
|
+
detailedFilter: sharedDetailedFilterSchema.optional(),
|
|
104
|
+
exportType: sharedReportExportTypeSchema,
|
|
105
|
+
summaryFilter: sharedSummaryFilterSchema.optional(),
|
|
106
|
+
weeklyFilter: sharedWeeklyFilterSchema.optional(),
|
|
107
|
+
})
|
|
108
|
+
.strict();
|
|
109
|
+
const sharedReportBodyShape = {
|
|
110
|
+
filter: sharedReportFilterSchema,
|
|
111
|
+
isPublic: z.boolean().optional(),
|
|
112
|
+
name: nonEmptyStringSchema,
|
|
113
|
+
type: sharedReportTypeSchema,
|
|
114
|
+
};
|
|
115
|
+
const sharedReportCreateBodySchema = z.object(sharedReportBodyShape).strict();
|
|
116
|
+
const sharedReportUpdateBodySchema = z.object(sharedReportBodyShape).strict();
|
|
117
|
+
function toSharedReportFilter(value) {
|
|
118
|
+
return {
|
|
119
|
+
dateRangeEnd: value.dateRangeEnd,
|
|
120
|
+
dateRangeStart: value.dateRangeStart,
|
|
121
|
+
exportType: value.exportType,
|
|
122
|
+
...(value.attendanceFilter !== undefined
|
|
123
|
+
? {
|
|
124
|
+
attendanceFilter: {
|
|
125
|
+
...(value.attendanceFilter.page !== undefined
|
|
126
|
+
? { page: value.attendanceFilter.page }
|
|
127
|
+
: {}),
|
|
128
|
+
...(value.attendanceFilter.pageSize !== undefined
|
|
129
|
+
? { pageSize: value.attendanceFilter.pageSize }
|
|
130
|
+
: {}),
|
|
131
|
+
...(value.attendanceFilter.users !== undefined
|
|
132
|
+
? { users: value.attendanceFilter.users }
|
|
133
|
+
: {}),
|
|
134
|
+
},
|
|
135
|
+
}
|
|
136
|
+
: {}),
|
|
137
|
+
...(value.detailedFilter !== undefined
|
|
138
|
+
? {
|
|
139
|
+
detailedFilter: {
|
|
140
|
+
...(value.detailedFilter.auditFilter !== undefined
|
|
141
|
+
? { auditFilter: value.detailedFilter.auditFilter }
|
|
142
|
+
: {}),
|
|
143
|
+
...(value.detailedFilter.options !== undefined
|
|
144
|
+
? { options: value.detailedFilter.options }
|
|
145
|
+
: {}),
|
|
146
|
+
...(value.detailedFilter.page !== undefined
|
|
147
|
+
? { page: value.detailedFilter.page }
|
|
148
|
+
: {}),
|
|
149
|
+
...(value.detailedFilter.pageSize !== undefined
|
|
150
|
+
? { pageSize: value.detailedFilter.pageSize }
|
|
151
|
+
: {}),
|
|
152
|
+
...(value.detailedFilter.sortColumn !== undefined
|
|
153
|
+
? { sortColumn: value.detailedFilter.sortColumn }
|
|
154
|
+
: {}),
|
|
155
|
+
...(value.detailedFilter.sortOrder !== undefined
|
|
156
|
+
? { sortOrder: value.detailedFilter.sortOrder }
|
|
157
|
+
: {}),
|
|
158
|
+
},
|
|
159
|
+
}
|
|
160
|
+
: {}),
|
|
161
|
+
...(value.summaryFilter !== undefined
|
|
162
|
+
? {
|
|
163
|
+
summaryFilter: {
|
|
164
|
+
groups: value.summaryFilter.groups,
|
|
165
|
+
...(value.summaryFilter.sortColumn !== undefined
|
|
166
|
+
? { sortColumn: value.summaryFilter.sortColumn }
|
|
167
|
+
: {}),
|
|
168
|
+
},
|
|
169
|
+
}
|
|
170
|
+
: {}),
|
|
171
|
+
...(value.weeklyFilter !== undefined
|
|
172
|
+
? {
|
|
173
|
+
weeklyFilter: {
|
|
174
|
+
group: value.weeklyFilter.group,
|
|
175
|
+
subgroup: value.weeklyFilter.subgroup,
|
|
176
|
+
},
|
|
177
|
+
}
|
|
178
|
+
: {}),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
function toSharedReportBody(value) {
|
|
182
|
+
return {
|
|
183
|
+
filter: toSharedReportFilter(value.filter),
|
|
184
|
+
name: value.name,
|
|
185
|
+
type: value.type,
|
|
186
|
+
...(value.isPublic !== undefined ? { isPublic: value.isPublic } : {}),
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
function parseFilterJson(raw) {
|
|
190
|
+
if (typeof raw !== "string") {
|
|
191
|
+
throw new Error("--filter must be a JSON object.");
|
|
192
|
+
}
|
|
37
193
|
try {
|
|
38
|
-
|
|
39
|
-
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
40
|
-
throw new Error("not an object");
|
|
41
|
-
}
|
|
42
|
-
return parsed;
|
|
194
|
+
return JSON.parse(raw);
|
|
43
195
|
}
|
|
44
196
|
catch {
|
|
45
197
|
throw new Error(`--filter must be a JSON object, e.g. '{"dateRangeStart":"…","dateRangeEnd":"…"}'`);
|
|
46
198
|
}
|
|
47
199
|
}
|
|
48
|
-
function
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
|
|
200
|
+
function schemaIssueLabel(issue, operation) {
|
|
201
|
+
const [root, ...path] = issue.path;
|
|
202
|
+
if (root === "filter") {
|
|
203
|
+
return path.length > 0 ? `--filter ${path.join(".")}` : "--filter";
|
|
52
204
|
}
|
|
53
|
-
|
|
205
|
+
if (root === "name")
|
|
206
|
+
return "--name";
|
|
207
|
+
if (root === "type")
|
|
208
|
+
return "--type";
|
|
209
|
+
return operation;
|
|
210
|
+
}
|
|
211
|
+
function sharedReportValidationError(error, operation, rawType) {
|
|
212
|
+
const invalidTypeIssue = error.issues.find((issue) => issue.path[0] === "type" && issue.code === z.ZodIssueCode.invalid_enum_value);
|
|
213
|
+
if (invalidTypeIssue !== undefined) {
|
|
214
|
+
return new Error(`Unknown --type "${String(rawType)}". Use one of: ${SHARED_REPORT_TYPES.join(", ")}.`);
|
|
215
|
+
}
|
|
216
|
+
const issue = error.issues[0];
|
|
217
|
+
if (issue === undefined)
|
|
218
|
+
return new Error(`${operation}: invalid request.`);
|
|
219
|
+
if (issue.path.length === 1 &&
|
|
220
|
+
issue.path[0] === "filter" &&
|
|
221
|
+
issue.code === z.ZodIssueCode.invalid_type &&
|
|
222
|
+
issue.expected === "object") {
|
|
223
|
+
return new Error("--filter must be a JSON object.");
|
|
224
|
+
}
|
|
225
|
+
const label = schemaIssueLabel(issue, operation);
|
|
226
|
+
if (issue.code === z.ZodIssueCode.unrecognized_keys) {
|
|
227
|
+
const fieldKind = issue.path[0] === "filter" ? "filter field(s)" : "field(s)";
|
|
228
|
+
return new Error(`${label} has unknown ${fieldKind}: ${issue.keys.join(", ")}.`);
|
|
229
|
+
}
|
|
230
|
+
return new Error(`${label}: ${issue.message}`);
|
|
231
|
+
}
|
|
232
|
+
function parseSharedReportBody(schema, opts, operation) {
|
|
233
|
+
const candidate = {
|
|
234
|
+
name: opts.name,
|
|
235
|
+
type: opts.type,
|
|
236
|
+
filter: parseFilterJson(opts.filter),
|
|
237
|
+
...(opts.public === true ? { isPublic: true } : {}),
|
|
238
|
+
};
|
|
239
|
+
const result = schema.safeParse(candidate);
|
|
240
|
+
if (!result.success) {
|
|
241
|
+
throw sharedReportValidationError(result.error, operation, opts.type);
|
|
242
|
+
}
|
|
243
|
+
return toSharedReportBody(result.data);
|
|
54
244
|
}
|
|
55
245
|
export const registerSharedReportsCommand = (program, services) => {
|
|
56
246
|
const shared = program
|
|
57
247
|
.command("shared-reports")
|
|
58
248
|
.description("Manage shared (public-link) reports.");
|
|
59
|
-
shared
|
|
60
|
-
.command("list")
|
|
249
|
+
leafCommand(shared, "list", "read")
|
|
61
250
|
.description("List the workspace's shared (public-link) reports.")
|
|
62
251
|
.action(async function () {
|
|
63
252
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
64
253
|
const result = await client.sharedReports.list({ workspaceId });
|
|
65
254
|
printObject(result, output);
|
|
66
255
|
});
|
|
67
|
-
shared
|
|
68
|
-
.command("view")
|
|
256
|
+
leafCommand(shared, "view", "read")
|
|
69
257
|
.argument("<id>", "Shared-report ID.")
|
|
70
258
|
.option("--export-type <type>", "Export type: JSON_V1, JSON, CSV, XLSX, or PDF (default JSON_V1).")
|
|
71
259
|
.description("View a shared report's rendered data by ID (reports host; not workspace-scoped).")
|
|
@@ -78,8 +266,7 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
78
266
|
});
|
|
79
267
|
printObject(await readReportBody(response), output);
|
|
80
268
|
});
|
|
81
|
-
shared
|
|
82
|
-
.command("create")
|
|
269
|
+
leafCommand(shared, "create", "write")
|
|
83
270
|
.requiredOption("--name <text>", "Shared-report name.")
|
|
84
271
|
.requiredOption("--type <type>", `Report type: ${SHARED_REPORT_TYPES.join(", ")}.`)
|
|
85
272
|
.requiredOption("--filter <json>", "Report filter object as a JSON string.")
|
|
@@ -87,14 +274,9 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
87
274
|
.description("Create a shared (public-link) report.")
|
|
88
275
|
.action(async function (opts) {
|
|
89
276
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
90
|
-
const body =
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
filter: parseFilter(opts.filter),
|
|
94
|
-
};
|
|
95
|
-
if (opts.public)
|
|
96
|
-
body.isPublic = true;
|
|
97
|
-
const created = (await client.sharedReports.create(wireBody({ workspaceId, body })));
|
|
277
|
+
const body = parseSharedReportBody(sharedReportCreateBodySchema, opts, "shared-reports.create");
|
|
278
|
+
const request = { workspaceId, body };
|
|
279
|
+
const created = (await client.sharedReports.create(request));
|
|
98
280
|
const data = { id: created.id ?? "", name: created.name ?? opts.name };
|
|
99
281
|
printReceipt({
|
|
100
282
|
ok: true,
|
|
@@ -111,8 +293,7 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
111
293
|
],
|
|
112
294
|
}, output);
|
|
113
295
|
});
|
|
114
|
-
shared
|
|
115
|
-
.command("update")
|
|
296
|
+
leafCommand(shared, "update", "write")
|
|
116
297
|
.argument("<id>", "Shared-report ID.")
|
|
117
298
|
.requiredOption("--name <text>", "Shared-report name.")
|
|
118
299
|
.requiredOption("--type <type>", `Report type: ${SHARED_REPORT_TYPES.join(", ")}.`)
|
|
@@ -121,18 +302,13 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
121
302
|
.description("Replace a shared report by ID (full replace of name, type, and filter).")
|
|
122
303
|
.action(async function (id, opts) {
|
|
123
304
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
124
|
-
const body =
|
|
125
|
-
|
|
126
|
-
type: requireType(opts.type),
|
|
127
|
-
filter: parseFilter(opts.filter),
|
|
128
|
-
};
|
|
129
|
-
if (opts.public)
|
|
130
|
-
body.isPublic = true;
|
|
131
|
-
const updated = (await client.sharedReports.update(wireBody({
|
|
305
|
+
const body = parseSharedReportBody(sharedReportUpdateBodySchema, opts, "shared-reports.update");
|
|
306
|
+
const request = {
|
|
132
307
|
workspaceId,
|
|
133
308
|
sharedReportId: id,
|
|
134
309
|
body,
|
|
135
|
-
}
|
|
310
|
+
};
|
|
311
|
+
const updated = (await client.sharedReports.update(request));
|
|
136
312
|
const data = { id: updated.id ?? id, name: updated.name ?? opts.name };
|
|
137
313
|
printReceipt({
|
|
138
314
|
ok: true,
|
|
@@ -149,8 +325,7 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
149
325
|
],
|
|
150
326
|
}, output);
|
|
151
327
|
});
|
|
152
|
-
shared
|
|
153
|
-
.command("delete")
|
|
328
|
+
leafCommand(shared, "delete", "destructive")
|
|
154
329
|
.argument("<id>", "Shared-report ID.")
|
|
155
330
|
.description("Delete a shared report by ID.")
|
|
156
331
|
.action(async function (id) {
|
package/dist/commands/start.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { entityId } from "clockify-sdk-ts-115/operation-receipt";
|
|
2
2
|
import { printReceipt } from "../receipt.js";
|
|
3
3
|
import { resolveContext } from "./helpers.js";
|
|
4
|
+
import { leafCommand } from "./leaf-command.js";
|
|
4
5
|
import { resolveProjectId, resolveTaskId, resolveTagIds } from "./resolve-refs.js";
|
|
5
6
|
export const registerStartCommand = (program, services) => {
|
|
6
|
-
program
|
|
7
|
-
.command("start")
|
|
7
|
+
leafCommand(program, "start", "write")
|
|
8
8
|
.description("Start a running time entry. Resolves project/task/tag names to IDs automatically.")
|
|
9
9
|
.argument("[description]", "Description for the time entry.")
|
|
10
10
|
.option("-p, --project <name>", "Project name or ID.")
|
package/dist/commands/status.js
CHANGED
|
@@ -2,9 +2,9 @@ import { entityId } from "clockify-sdk-ts-115/operation-receipt";
|
|
|
2
2
|
import { formatIsoDuration } from "../duration.js";
|
|
3
3
|
import { printObject } from "../output.js";
|
|
4
4
|
import { resolveBaseContext } from "./helpers.js";
|
|
5
|
+
import { leafCommand } from "./leaf-command.js";
|
|
5
6
|
export const registerStatusCommand = (program, services) => {
|
|
6
|
-
program
|
|
7
|
-
.command("status")
|
|
7
|
+
leafCommand(program, "status", "read")
|
|
8
8
|
.description("Show the configured workspace, current user, and running timer.")
|
|
9
9
|
.action(async function () {
|
|
10
10
|
const { client, config, output } = await resolveBaseContext(this, services);
|
|
@@ -35,7 +35,7 @@ export const registerStatusCommand = (program, services) => {
|
|
|
35
35
|
description: running.description ?? "",
|
|
36
36
|
projectId: running.projectId ?? "",
|
|
37
37
|
startedAt: extractStart(running),
|
|
38
|
-
elapsed:
|
|
38
|
+
elapsed: formatRunningElapsed(running),
|
|
39
39
|
}
|
|
40
40
|
: "(no timer running)",
|
|
41
41
|
}, output);
|
|
@@ -64,3 +64,27 @@ function extractIsoDuration(entry) {
|
|
|
64
64
|
const interval = entry.timeInterval;
|
|
65
65
|
return interval?.duration ?? null;
|
|
66
66
|
}
|
|
67
|
+
function humanizeSeconds(total) {
|
|
68
|
+
if (total <= 0)
|
|
69
|
+
return "0s";
|
|
70
|
+
const hours = Math.floor(total / 3600);
|
|
71
|
+
const minutes = Math.floor((total % 3600) / 60);
|
|
72
|
+
const seconds = total % 60;
|
|
73
|
+
const parts = [];
|
|
74
|
+
if (hours)
|
|
75
|
+
parts.push(`${hours}h`);
|
|
76
|
+
if (minutes)
|
|
77
|
+
parts.push(`${minutes}m`);
|
|
78
|
+
if (seconds)
|
|
79
|
+
parts.push(`${seconds}s`);
|
|
80
|
+
return parts.length > 0 ? parts.join("") : "0s";
|
|
81
|
+
}
|
|
82
|
+
function formatRunningElapsed(entry) {
|
|
83
|
+
const iso = extractIsoDuration(entry);
|
|
84
|
+
if (iso)
|
|
85
|
+
return formatIsoDuration(iso);
|
|
86
|
+
const startMs = Date.parse(extractStart(entry));
|
|
87
|
+
if (!Number.isFinite(startMs))
|
|
88
|
+
return "0s";
|
|
89
|
+
return humanizeSeconds(Math.max(0, Math.round((Date.now() - startMs) / 1000)));
|
|
90
|
+
}
|
package/dist/commands/stop.js
CHANGED
|
@@ -2,9 +2,9 @@ import { entityId } from "clockify-sdk-ts-115/operation-receipt";
|
|
|
2
2
|
import { printSuccess } from "../output.js";
|
|
3
3
|
import { printReceipt } from "../receipt.js";
|
|
4
4
|
import { resolveContext } from "./helpers.js";
|
|
5
|
+
import { leafCommand } from "./leaf-command.js";
|
|
5
6
|
export const registerStopCommand = (program, services) => {
|
|
6
|
-
program
|
|
7
|
-
.command("stop")
|
|
7
|
+
leafCommand(program, "stop", "write")
|
|
8
8
|
.description("Stop the running timer for the current user.")
|
|
9
9
|
.action(async function () {
|
|
10
10
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
package/dist/commands/tags.js
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { printObject, printRecords } from "../output.js";
|
|
2
2
|
import { printReceipt } from "../receipt.js";
|
|
3
3
|
import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
|
|
4
|
+
import { leafCommand } from "./leaf-command.js";
|
|
4
5
|
export const registerTagsCommand = (program, services) => {
|
|
5
6
|
const tags = program.command("tags").description("Manage tags.");
|
|
6
|
-
tags
|
|
7
|
+
leafCommand(tags, "list", "read")
|
|
7
8
|
.description("List tags in the workspace.")
|
|
8
9
|
.option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
|
|
9
10
|
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
10
11
|
.option("--name <text>", "Filter by tag name substring.")
|
|
11
|
-
.option("--archived", "
|
|
12
|
+
.option("--archived", "Show only archived tags (default lists both archived and active).", false)
|
|
12
13
|
.action(async function (opts) {
|
|
13
14
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
14
15
|
const req = {
|
|
@@ -31,7 +32,7 @@ export const registerTagsCommand = (program, services) => {
|
|
|
31
32
|
});
|
|
32
33
|
printRecords(rows, output);
|
|
33
34
|
});
|
|
34
|
-
tags
|
|
35
|
+
leafCommand(tags, "create", "write")
|
|
35
36
|
.argument("<name>", "Tag name.")
|
|
36
37
|
.description("Create a tag in the workspace.")
|
|
37
38
|
.action(async function (name) {
|
|
@@ -51,7 +52,7 @@ export const registerTagsCommand = (program, services) => {
|
|
|
51
52
|
],
|
|
52
53
|
}, output);
|
|
53
54
|
});
|
|
54
|
-
tags
|
|
55
|
+
leafCommand(tags, "get", "read")
|
|
55
56
|
.argument("<id>", "Tag ID.")
|
|
56
57
|
.description("Get one tag by ID.")
|
|
57
58
|
.action(async function (id) {
|
|
@@ -59,7 +60,7 @@ export const registerTagsCommand = (program, services) => {
|
|
|
59
60
|
const tag = await client.tags.get({ workspaceId, tagId: id });
|
|
60
61
|
printObject(tag, output);
|
|
61
62
|
});
|
|
62
|
-
tags
|
|
63
|
+
leafCommand(tags, "update", "write")
|
|
63
64
|
.argument("<id>", "Tag ID.")
|
|
64
65
|
.option("--name <text>", "New tag name.")
|
|
65
66
|
.option("--archived", "Archive the tag.")
|
|
@@ -85,7 +86,7 @@ export const registerTagsCommand = (program, services) => {
|
|
|
85
86
|
next: [{ command: "clk115 tags list --json", reason: "Verify the update." }],
|
|
86
87
|
}, output);
|
|
87
88
|
});
|
|
88
|
-
tags
|
|
89
|
+
leafCommand(tags, "delete", "destructive")
|
|
89
90
|
.argument("<id>", "Tag ID.")
|
|
90
91
|
.description("Delete a tag by ID.")
|
|
91
92
|
.action(async function (id) {
|