@apet97/clockify-cli-115 5.0.4 → 7.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 +255 -39
- package/dist/client.js +43 -17
- package/dist/closed-pipe.js +3 -0
- package/dist/commands/api.js +192 -103
- package/dist/commands/approvals.js +9 -10
- package/dist/commands/auditlog.js +11 -8
- package/dist/commands/auth.js +229 -0
- package/dist/commands/balanceAssignment.js +10 -8
- package/dist/commands/batch.js +226 -0
- package/dist/commands/clients.js +27 -72
- package/dist/commands/doctor.js +98 -82
- package/dist/commands/entries.js +29 -14
- package/dist/commands/expenses.js +75 -36
- package/dist/commands/helpers.js +74 -9
- package/dist/commands/invoices.js +12 -16
- package/dist/commands/leaf-command.js +15 -0
- package/dist/commands/log.js +4 -2
- package/dist/commands/manifest.js +63 -0
- package/dist/commands/operations.js +271 -0
- package/dist/commands/projects.js +28 -32
- package/dist/commands/reports.js +54 -21
- package/dist/commands/resolve-refs.js +30 -53
- package/dist/commands/scheduling.js +94 -40
- package/dist/commands/shared-report-body.js +127 -0
- package/dist/commands/sharedReports.js +19 -235
- package/dist/commands/skill.js +85 -0
- package/dist/commands/start.js +6 -4
- package/dist/commands/status.js +69 -27
- package/dist/commands/stop.js +7 -18
- package/dist/commands/tags.js +11 -11
- package/dist/commands/tasks.js +27 -133
- package/dist/commands/timeoff.js +23 -16
- package/dist/commands/users.js +11 -19
- package/dist/commands/webhook-delivery.js +331 -0
- package/dist/commands/webhooks.js +40 -104
- package/dist/completions.js +291 -55
- package/dist/config.js +168 -61
- package/dist/credentials.js +164 -0
- package/dist/duration.js +5 -4
- package/dist/failure.js +82 -0
- package/dist/flags.js +84 -0
- package/dist/generated/version.js +1 -1
- package/dist/index.js +68 -108
- package/dist/interrupts.js +28 -0
- package/dist/output.js +189 -66
- package/dist/receipt.js +2 -10
- package/dist/stdin.js +6 -0
- package/dist/stdout.js +38 -0
- package/dist/write-outcome.js +84 -0
- package/package.json +6 -4
- package/plugin/.claude-plugin/plugin.json +16 -0
- package/plugin/skills/clockify-cli/SKILL.md +88 -0
- package/plugin/skills/clockify-mcp/SKILL.md +48 -0
- package/plugin/skills/clockify-sdk/SKILL.md +85 -0
- package/dist/error-codes.js +0 -272
package/dist/commands/api.js
CHANGED
|
@@ -1,88 +1,153 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { AlreadyReportedError,
|
|
4
|
-
import {
|
|
1
|
+
import { UsageError } from "../failure.js";
|
|
2
|
+
import { resolveFlags } from "../flags.js";
|
|
3
|
+
import { AlreadyReportedError, printData } from "../output.js";
|
|
4
|
+
import { dispatchedWrite, writeFailure } from "../write-outcome.js";
|
|
5
|
+
import { collect, parseIntArg, parseJson, parsePair, printScan, readTextInput, resolveBaseContext, rootProgram } from "./helpers.js";
|
|
5
6
|
import { leafCommand } from "./leaf-command.js";
|
|
6
7
|
const METHODS = new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
8
|
+
const CREDENTIAL_HEADERS = new Set(["x-api-key", "x-addon-token"]);
|
|
9
|
+
const HEADER_NAME = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
7
10
|
export const registerApiCommand = (program, services) => {
|
|
8
11
|
leafCommand(program, "api", "destructive")
|
|
9
12
|
.description("Call a Clockify API path directly through the SDK client.")
|
|
10
13
|
.addHelpText("after", "\nExamples:\n" +
|
|
11
14
|
" $ clk115 api GET /workspaces/{workspaceId}/tags\n" +
|
|
12
15
|
" $ clk115 api POST /workspaces/{workspaceId}/tags --body '{\"name\":\"focus\"}'\n" +
|
|
13
|
-
" $ clk115 api GET /workspaces/{workspaceId}/projects --all --page-size 100\n"
|
|
16
|
+
" $ clk115 api GET /workspaces/{workspaceId}/projects --all --page-size 100\n" +
|
|
17
|
+
"\nPaths resolve against the regular API base (https://api.clockify.me/api/v1).\n" +
|
|
18
|
+
"Reports-host endpoints need --base-url https://reports.api.clockify.me/v1,\n" +
|
|
19
|
+
"or use the curated `clk115 reports` and `clk115 audit-log` commands.\n")
|
|
14
20
|
.argument("<method>", "HTTP method: GET, POST, PUT, PATCH, or DELETE.")
|
|
15
21
|
.argument("<path>", "API path, e.g. /workspaces/{workspaceId}/tags.")
|
|
16
22
|
.option("-q, --query <key=value>", "Query parameter (repeatable).", collect, [])
|
|
17
|
-
.option("-H, --header <key=value>", "Request header (repeatable).", collect, [])
|
|
23
|
+
.option("-H, --header <key=value>", "Request header as key=value or 'Key: value' (repeatable).", collect, [])
|
|
18
24
|
.option("--body <json|@file|->", "JSON body: inline, @file, or - for stdin.")
|
|
19
|
-
.option("--all", "
|
|
25
|
+
.option("--all", "Read every page of a list, honoring Last-Page when present.", false)
|
|
20
26
|
.option("--page-size <n>", "Page size for --all.", parseIntArg, 50)
|
|
21
27
|
.option("--max-pages <n>", "Maximum pages for --all.", parseIntArg, 20)
|
|
28
|
+
.option("--require-complete", "Print the rows, then exit 1 unless --all is known to have read every page.", false)
|
|
22
29
|
.option("--include-headers", "Include status and response headers in output.", false)
|
|
23
30
|
.action(async function (methodArg, pathArg, options) {
|
|
24
|
-
const { client, config, output } = await resolveBaseContext(this, services);
|
|
25
31
|
const method = methodArg.toUpperCase();
|
|
26
32
|
if (!METHODS.has(method)) {
|
|
27
|
-
throw new
|
|
33
|
+
throw new UsageError(`Unsupported method "${methodArg}". Provide one of: GET, POST, PUT, PATCH, DELETE.`);
|
|
28
34
|
}
|
|
35
|
+
requireRelativePath(pathArg);
|
|
36
|
+
const query = options.query.map((value) => parsePair(value, "--query"));
|
|
37
|
+
const headers = parseHeaders(options.header);
|
|
38
|
+
validatePagingFlags(this, method, options);
|
|
39
|
+
const body = await readTextInput(options.body, "--body");
|
|
40
|
+
if (body !== undefined && method === "GET") {
|
|
41
|
+
throw new UsageError("--body cannot be sent with GET; use POST, PUT, PATCH, or DELETE.");
|
|
42
|
+
}
|
|
43
|
+
if (body !== undefined && !hasHeader(headers, "content-type")) {
|
|
44
|
+
parseJson(body, "--body", "set a Content-Type header to send another format");
|
|
45
|
+
}
|
|
46
|
+
const output = resolveFlags(rootProgram(this));
|
|
47
|
+
const binaryConflict = process.stdout.isTTY || output.mode !== "table" || options.includeHeaders || options.all;
|
|
48
|
+
const accept = new Headers(headers).get("accept");
|
|
49
|
+
if (binaryConflict && accept && accept.split(",").every(type => !type.includes("*") && isBinaryMediaType(type))) {
|
|
50
|
+
throw new UsageError("Binary Accept header: redirect or pipe stdout without JSON, NDJSON, --all, or --include-headers.");
|
|
51
|
+
}
|
|
52
|
+
const { client, config } = await resolveBaseContext(this, services, output);
|
|
29
53
|
const path = resolvePath(pathArg, config.workspaceId);
|
|
30
|
-
const query = parseQueryPairs(options.query);
|
|
31
|
-
const headers = parsePairs(options.header);
|
|
32
54
|
if (options.all) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
55
|
+
const { items, stop } = await fetchAllPages(client, path, query, headers, options.pageSize, options.maxPages);
|
|
56
|
+
const gap = {
|
|
57
|
+
complete: undefined,
|
|
58
|
+
repeated: "The endpoint ignores pagination (repeated page); returning the preceding pages.",
|
|
59
|
+
truncated: `--all stopped at the --max-pages limit (${options.maxPages}); the results are incomplete. Re-run with a larger --max-pages.`,
|
|
60
|
+
}[stop];
|
|
61
|
+
printScan(() => { printData(items, output); }, gap, options.requireComplete, output);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const request = client.fetch(path, requestInit(method, headers, body), queryParams(query));
|
|
65
|
+
const response = method === "GET" ? await request : await dispatchedWrite(this, request);
|
|
66
|
+
if (isBinaryResponse(response)) {
|
|
67
|
+
if (!response.ok || binaryConflict) {
|
|
68
|
+
await response.body?.cancel().catch(() => undefined);
|
|
69
|
+
if (!response.ok)
|
|
70
|
+
throw await rawApiError(response, undefined);
|
|
71
|
+
throw Object.assign(new Error("Binary response: redirect or pipe stdout without JSON, NDJSON, or --include-headers."), { statusCode: response.status });
|
|
43
72
|
}
|
|
44
|
-
|
|
73
|
+
process.stdout.write(Buffer.from(await response.arrayBuffer()));
|
|
45
74
|
return;
|
|
46
75
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
throw Object.assign(new Error(`HTTP ${response.status}: ${formatBody(data)}`), {
|
|
52
|
-
statusCode: response.status,
|
|
53
|
-
});
|
|
76
|
+
if (response.ok) {
|
|
77
|
+
const data = await readResponseData(response);
|
|
78
|
+
printData(responsePayload(response, data, options.includeHeaders), output);
|
|
79
|
+
return;
|
|
54
80
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
81
|
+
const { data, readError } = await readErrorData(response);
|
|
82
|
+
const cause = await rawApiError(response, data, undefined, readError);
|
|
83
|
+
if (!options.includeHeaders)
|
|
84
|
+
throw cause;
|
|
85
|
+
const payload = {
|
|
86
|
+
status: response.status,
|
|
87
|
+
headers: Object.fromEntries(response.headers),
|
|
88
|
+
data,
|
|
89
|
+
...(readError && { bodyError: readError.message }),
|
|
90
|
+
};
|
|
91
|
+
const write = await writeFailure(this, cause);
|
|
92
|
+
if (write) {
|
|
93
|
+
const { classifyClockifyError } = await import("clockify-sdk-ts-115/errors");
|
|
94
|
+
const classified = classifyClockifyError(cause);
|
|
95
|
+
Object.assign(payload, { retryable: classified?.retryable, recovery: classified?.recovery }, write);
|
|
58
96
|
}
|
|
97
|
+
printData(payload, output);
|
|
98
|
+
throw new AlreadyReportedError();
|
|
59
99
|
});
|
|
60
100
|
};
|
|
61
|
-
function
|
|
62
|
-
|
|
63
|
-
|
|
101
|
+
function parseHeaders(values) {
|
|
102
|
+
const headers = {};
|
|
103
|
+
for (const value of values) {
|
|
104
|
+
const colon = value.indexOf(":");
|
|
105
|
+
const equals = value.indexOf("=");
|
|
106
|
+
const [rawKey, rawValue] = colon > 0 && (equals === -1 || colon < equals)
|
|
107
|
+
? [value.slice(0, colon).trim(), value.slice(colon + 1).trim()]
|
|
108
|
+
: parsePair(value, "--header");
|
|
109
|
+
if (!HEADER_NAME.test(rawKey)) {
|
|
110
|
+
throw new UsageError(`--header name ${JSON.stringify(rawKey)} is not a valid HTTP header name.`);
|
|
111
|
+
}
|
|
112
|
+
if (/[\r\n\0]/.test(rawValue)) {
|
|
113
|
+
throw new UsageError(`--header ${rawKey} value must not contain CR, LF, or NUL characters.`);
|
|
114
|
+
}
|
|
115
|
+
if (CREDENTIAL_HEADERS.has(rawKey.toLowerCase())) {
|
|
116
|
+
throw new UsageError(`--header ${rawKey} is not accepted: the SDK sets credentials itself. Provide them through CLOCKIFY_API_KEY or CLOCKIFY_ADDON_TOKEN.`);
|
|
117
|
+
}
|
|
118
|
+
headers[rawKey] = rawValue;
|
|
119
|
+
}
|
|
120
|
+
return headers;
|
|
64
121
|
}
|
|
65
|
-
function
|
|
66
|
-
return Object.
|
|
122
|
+
function hasHeader(headers, name) {
|
|
123
|
+
return Object.keys(headers).some((key) => key.toLowerCase() === name);
|
|
67
124
|
}
|
|
68
|
-
function
|
|
69
|
-
|
|
125
|
+
function requireRelativePath(path) {
|
|
126
|
+
if (!path.startsWith("/") || path.startsWith("//")) {
|
|
127
|
+
throw new UsageError("API path must start with a single /, relative to the API base URL (e.g. /workspaces/{workspaceId}/tags).");
|
|
128
|
+
}
|
|
70
129
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
130
|
+
function validatePagingFlags(command, method, options) {
|
|
131
|
+
if (!options.all) {
|
|
132
|
+
for (const [option, flag] of [
|
|
133
|
+
["pageSize", "--page-size"],
|
|
134
|
+
["maxPages", "--max-pages"],
|
|
135
|
+
["requireComplete", "--require-complete"],
|
|
136
|
+
]) {
|
|
137
|
+
if (command.getOptionValueSource(option) === "cli") {
|
|
138
|
+
throw new UsageError(`${flag} only applies with --all; for a single page pass -q page-size=N instead.`);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return;
|
|
75
142
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
143
|
+
if (method !== "GET") {
|
|
144
|
+
throw new UsageError("--all is only supported for GET requests.");
|
|
145
|
+
}
|
|
146
|
+
if (options.includeHeaders) {
|
|
147
|
+
throw new UsageError("--include-headers is not supported with --all; each page's status and headers are consumed by the pagination walk.");
|
|
79
148
|
}
|
|
80
|
-
return [key, value.slice(index + 1)];
|
|
81
149
|
}
|
|
82
150
|
function resolvePath(path, workspaceId) {
|
|
83
|
-
if (!path.startsWith("/")) {
|
|
84
|
-
throw new Error("API path must start with /.");
|
|
85
|
-
}
|
|
86
151
|
if (path.includes("{workspaceId}")) {
|
|
87
152
|
if (!workspaceId) {
|
|
88
153
|
throw new Error("Path uses {workspaceId}; provide --workspace or CLOCKIFY_WORKSPACE_ID.");
|
|
@@ -91,16 +156,11 @@ function resolvePath(path, workspaceId) {
|
|
|
91
156
|
}
|
|
92
157
|
return path;
|
|
93
158
|
}
|
|
94
|
-
function
|
|
95
|
-
const
|
|
96
|
-
const base = qIndex === -1 ? path : path.slice(0, qIndex);
|
|
97
|
-
const params = new URLSearchParams(qIndex === -1 ? "" : path.slice(qIndex + 1));
|
|
98
|
-
for (const key of new Set(query.map(([name]) => name)))
|
|
99
|
-
params.delete(key);
|
|
159
|
+
function queryParams(query) {
|
|
160
|
+
const params = {};
|
|
100
161
|
for (const [key, value] of query)
|
|
101
|
-
params.
|
|
102
|
-
|
|
103
|
-
return search ? `${base}?${search}` : base;
|
|
162
|
+
(params[key] ??= []).push(value);
|
|
163
|
+
return { queryParams: params };
|
|
104
164
|
}
|
|
105
165
|
function requestInit(method, headers, body) {
|
|
106
166
|
const merged = { ...headers };
|
|
@@ -113,61 +173,74 @@ function requestInit(method, headers, body) {
|
|
|
113
173
|
}
|
|
114
174
|
return init;
|
|
115
175
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
176
|
+
const PAGE_SIZE_NAMES = ["page-size", "pageSize", "size", "limit"];
|
|
177
|
+
const LARGEST_PAGE = 200;
|
|
178
|
+
async function pagingOf(path) {
|
|
179
|
+
const { operations } = await import("clockify-sdk-ts-115/operations");
|
|
180
|
+
const segments = path.split("?", 1)[0]?.split("/") ?? [];
|
|
181
|
+
for (const operation of operations().values()) {
|
|
182
|
+
const { page, ...query } = operation.input.properties?.query?.properties ?? {};
|
|
183
|
+
const sizeName = PAGE_SIZE_NAMES.find((name) => name in query);
|
|
184
|
+
const template = operation.path.split("/");
|
|
185
|
+
if (operation.method === "GET" &&
|
|
186
|
+
page &&
|
|
187
|
+
sizeName &&
|
|
188
|
+
template.length === segments.length &&
|
|
189
|
+
template.every((part, index) => part.startsWith("{") || part === segments[index])) {
|
|
190
|
+
return { first: Number(page.default ?? 1), sizeName };
|
|
128
191
|
}
|
|
129
192
|
}
|
|
130
|
-
return
|
|
193
|
+
return { first: 1, sizeName: "page-size" };
|
|
131
194
|
}
|
|
132
195
|
async function fetchAllPages(client, path, query, headers, pageSize, maxPages) {
|
|
133
196
|
const items = [];
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
197
|
+
const { first, sizeName } = await pagingOf(path);
|
|
198
|
+
const callerQuery = query.filter(([key]) => key !== "page" && key !== sizeName);
|
|
199
|
+
let state = { kind: "walking", page: first };
|
|
200
|
+
let previousPage;
|
|
201
|
+
while (state.kind === "walking") {
|
|
202
|
+
const page = state.page;
|
|
203
|
+
const paged = queryParams([
|
|
138
204
|
...callerQuery,
|
|
139
205
|
["page", String(page)],
|
|
140
|
-
[
|
|
206
|
+
[sizeName, String(pageSize)],
|
|
141
207
|
]);
|
|
142
|
-
const response = await client.fetch(
|
|
143
|
-
|
|
208
|
+
const response = await client.fetch(path, requestInit("GET", headers), paged);
|
|
209
|
+
if (isBinaryResponse(response)) {
|
|
210
|
+
await response.body?.cancel().catch(() => undefined);
|
|
211
|
+
if (!response.ok)
|
|
212
|
+
throw await rawApiError(response, undefined, page);
|
|
213
|
+
throw Object.assign(new Error("--all expects JSON pages; pipe a binary response without --all."), { statusCode: response.status });
|
|
214
|
+
}
|
|
144
215
|
if (!response.ok) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
});
|
|
216
|
+
const { data, readError } = await readErrorData(response);
|
|
217
|
+
throw await rawApiError(response, data, page, readError);
|
|
148
218
|
}
|
|
219
|
+
const data = await readResponseData(response);
|
|
149
220
|
if (!Array.isArray(data)) {
|
|
150
221
|
throw new Error("--all expects each page to return a JSON array.");
|
|
151
222
|
}
|
|
152
223
|
const lastPage = parseLastPageHeader(response.headers.get("Last-Page"));
|
|
153
|
-
|
|
154
|
-
if (
|
|
155
|
-
|
|
224
|
+
const fingerprint = JSON.stringify(data);
|
|
225
|
+
if (fingerprint === previousPage) {
|
|
226
|
+
state = { kind: "repeated" };
|
|
156
227
|
break;
|
|
157
228
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
229
|
+
previousPage = fingerprint;
|
|
230
|
+
items.push(...data);
|
|
231
|
+
if (data.length === 0 ||
|
|
232
|
+
lastPage === true ||
|
|
233
|
+
(lastPage === undefined && data.length < Math.min(pageSize, LARGEST_PAGE))) {
|
|
234
|
+
state = { kind: "complete" };
|
|
161
235
|
}
|
|
162
|
-
if (
|
|
163
|
-
|
|
236
|
+
else if (page - first + 1 >= maxPages) {
|
|
237
|
+
state = { kind: "truncated" };
|
|
164
238
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
break;
|
|
239
|
+
else {
|
|
240
|
+
state = { kind: "walking", page: page + 1 };
|
|
168
241
|
}
|
|
169
242
|
}
|
|
170
|
-
return { items,
|
|
243
|
+
return { items, stop: state.kind };
|
|
171
244
|
}
|
|
172
245
|
function parseLastPageHeader(value) {
|
|
173
246
|
if (value == null)
|
|
@@ -179,8 +252,23 @@ function parseLastPageHeader(value) {
|
|
|
179
252
|
return false;
|
|
180
253
|
return undefined;
|
|
181
254
|
}
|
|
182
|
-
function
|
|
183
|
-
|
|
255
|
+
async function rawApiError(response, body, page, cause) {
|
|
256
|
+
const { ClockifyApiError } = await import("clockify-sdk-ts-115");
|
|
257
|
+
return new ClockifyApiError({
|
|
258
|
+
message: `HTTP ${response.status}${page === undefined ? "" : ` on page ${page}`}`,
|
|
259
|
+
statusCode: response.status,
|
|
260
|
+
rawResponse: response,
|
|
261
|
+
body,
|
|
262
|
+
...(cause && { cause }),
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
function isBinaryResponse(response) {
|
|
266
|
+
return response.body !== null && isBinaryMediaType(response.headers.get("content-type") ?? "");
|
|
267
|
+
}
|
|
268
|
+
function isBinaryMediaType(value) {
|
|
269
|
+
const media = value.split(";", 1)[0]?.trim().toLowerCase();
|
|
270
|
+
return Boolean(media && !media.startsWith("text/") &&
|
|
271
|
+
!/(?:[+/](?:json|xml|javascript|x-www-form-urlencoded))$/.test(media));
|
|
184
272
|
}
|
|
185
273
|
async function readResponseData(response) {
|
|
186
274
|
const text = await response.text();
|
|
@@ -194,6 +282,14 @@ async function readResponseData(response) {
|
|
|
194
282
|
return text;
|
|
195
283
|
}
|
|
196
284
|
}
|
|
285
|
+
async function readErrorData(response) {
|
|
286
|
+
try {
|
|
287
|
+
return { data: await readResponseData(response) };
|
|
288
|
+
}
|
|
289
|
+
catch (cause) {
|
|
290
|
+
return { data: null, readError: cause instanceof Error ? cause : new Error(String(cause)) };
|
|
291
|
+
}
|
|
292
|
+
}
|
|
197
293
|
function responsePayload(response, data, includeHeaders) {
|
|
198
294
|
if (!includeHeaders) {
|
|
199
295
|
return data;
|
|
@@ -204,10 +300,3 @@ function responsePayload(response, data, includeHeaders) {
|
|
|
204
300
|
data,
|
|
205
301
|
};
|
|
206
302
|
}
|
|
207
|
-
function printApiOutput(value, output) {
|
|
208
|
-
if (output.mode === "ndjson") {
|
|
209
|
-
printNdjson(value, output);
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
printJson(value, output);
|
|
213
|
-
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { typedApprovalRequest } from "clockify-sdk-ts-115/requests";
|
|
2
|
+
import { UsageError } from "../failure.js";
|
|
1
3
|
import { printReceipt } from "../receipt.js";
|
|
4
|
+
import { dispatchedWrite } from "../write-outcome.js";
|
|
2
5
|
import { requireRfc3339Timestamp, resolveContext } from "./helpers.js";
|
|
3
6
|
import { leafCommand } from "./leaf-command.js";
|
|
4
7
|
const PERIODS = ["WEEKLY", "SEMI_MONTHLY", "MONTHLY"];
|
|
@@ -8,7 +11,7 @@ function requireEnum(value, allowed, flag) {
|
|
|
8
11
|
const upper = value.toUpperCase();
|
|
9
12
|
const match = allowed.find((candidate) => candidate === upper);
|
|
10
13
|
if (!match) {
|
|
11
|
-
throw new
|
|
14
|
+
throw new UsageError(`--${flag} must be one of: ${allowed.join(", ")} (got ${JSON.stringify(value)}).`);
|
|
12
15
|
}
|
|
13
16
|
return match;
|
|
14
17
|
}
|
|
@@ -32,17 +35,13 @@ export const registerApprovalsCommand = (program, services) => {
|
|
|
32
35
|
.action(async function (opts) {
|
|
33
36
|
const type = requireEnum(opts.type, SELF_TYPES, "type");
|
|
34
37
|
const periodStart = requireRfc3339Timestamp(opts.periodStart, "period-start");
|
|
35
|
-
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
36
38
|
const body = {
|
|
37
39
|
periodStart,
|
|
38
40
|
};
|
|
39
41
|
if (opts.period)
|
|
40
42
|
body.period = requireEnum(opts.period, PERIODS, "period");
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
approvalRequestId: type,
|
|
44
|
-
body,
|
|
45
|
-
});
|
|
43
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
44
|
+
const created = await dispatchedWrite(this, client.approvals.submitWithType(typedApprovalRequest({ workspaceId, type, body })));
|
|
46
45
|
const data = approvalReceiptData(created);
|
|
47
46
|
printReceipt({
|
|
48
47
|
ok: true,
|
|
@@ -71,18 +70,18 @@ export const registerApprovalsCommand = (program, services) => {
|
|
|
71
70
|
.action(async function (opts) {
|
|
72
71
|
const type = requireEnum(opts.type, OTHER_TYPES, "type");
|
|
73
72
|
const periodStart = requireRfc3339Timestamp(opts.periodStart, "period-start");
|
|
74
|
-
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
75
73
|
const body = {
|
|
76
74
|
periodStart,
|
|
77
75
|
};
|
|
78
76
|
if (opts.period)
|
|
79
77
|
body.period = requireEnum(opts.period, PERIODS, "period");
|
|
80
|
-
const
|
|
78
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
79
|
+
const created = await dispatchedWrite(this, client.approvals.submitForUserWithType({
|
|
81
80
|
workspaceId,
|
|
82
81
|
userId: opts.user,
|
|
83
82
|
type,
|
|
84
83
|
body,
|
|
85
|
-
});
|
|
84
|
+
}));
|
|
86
85
|
const data = approvalReceiptData(created);
|
|
87
86
|
printReceipt({
|
|
88
87
|
ok: true,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AUDIT_LOG_ACTIONS, } from "clockify-sdk-ts-115/requests";
|
|
2
|
+
import { UsageError } from "../failure.js";
|
|
2
3
|
import { printRecords } from "../output.js";
|
|
3
4
|
import { clampPageSize, parseIntArg, promoteDateBoundary, resolveContext, splitList, } from "./helpers.js";
|
|
4
5
|
import { leafCommand } from "./leaf-command.js";
|
|
@@ -7,7 +8,7 @@ export const registerAuditLogCommand = (program, services) => {
|
|
|
7
8
|
leafCommand(audit, "search", "read")
|
|
8
9
|
.description("Search the workspace audit log.")
|
|
9
10
|
.addHelpText("after", "\nExamples:\n" +
|
|
10
|
-
" $ clk115 audit-log search --start 2026-06-01 --end 2026-06-30\n")
|
|
11
|
+
" $ clk115 audit-log search --actions CREATE_PROJECT --start 2026-06-01 --end 2026-06-30\n")
|
|
11
12
|
.requiredOption("--start <date>", "Window start (YYYY-MM-DD or RFC3339, e.g. 2026-05-01T00:00:00Z).")
|
|
12
13
|
.requiredOption("--end <date>", "Window end (YYYY-MM-DD or RFC3339); the server caps the window at 31 days.")
|
|
13
14
|
.requiredOption("--actions <list>", "Comma-separated action names (e.g. CREATE_PROJECT,UPDATE_PROJECT).")
|
|
@@ -16,29 +17,31 @@ export const registerAuditLogCommand = (program, services) => {
|
|
|
16
17
|
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
17
18
|
.option("--limit <n>", "Items per page (default 50, max 50 — the audit-log server caps page size).", parseIntArg, 50)
|
|
18
19
|
.action(async function (opts) {
|
|
19
|
-
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
20
20
|
const actions = splitList(opts.actions).map((action) => action.toUpperCase());
|
|
21
21
|
if (actions.length === 0) {
|
|
22
|
-
throw new
|
|
22
|
+
throw new UsageError("--actions must include at least one action name");
|
|
23
23
|
}
|
|
24
24
|
const knownActions = new Set(AUDIT_LOG_ACTIONS);
|
|
25
25
|
const invalidActions = actions.filter((action) => !knownActions.has(action));
|
|
26
26
|
if (invalidActions.length > 0) {
|
|
27
|
-
throw new
|
|
27
|
+
throw new UsageError(`Unknown audit action(s): ${invalidActions.join(", ")}; provide known audit action names such as CREATE_PROJECT or UPDATE_PROJECT`);
|
|
28
28
|
}
|
|
29
29
|
const authorIds = opts.authors ? splitList(opts.authors) : [];
|
|
30
30
|
const mode = String(opts.authorsMode).toUpperCase();
|
|
31
31
|
if (mode !== "CONTAINS" && mode !== "DOES_NOT_CONTAIN") {
|
|
32
|
-
throw new
|
|
32
|
+
throw new UsageError(`--authors-mode must be CONTAINS or DOES_NOT_CONTAIN (got "${String(opts.authorsMode)}").`);
|
|
33
33
|
}
|
|
34
34
|
const authors = {
|
|
35
35
|
authorIds,
|
|
36
36
|
contains: mode,
|
|
37
37
|
};
|
|
38
|
+
const start = promoteDateBoundary(opts.start, "start", "start");
|
|
39
|
+
const end = promoteDateBoundary(opts.end, "end", "end");
|
|
40
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
38
41
|
const req = {
|
|
39
42
|
workspaceId,
|
|
40
|
-
start
|
|
41
|
-
end
|
|
43
|
+
start,
|
|
44
|
+
end,
|
|
42
45
|
actions: actions,
|
|
43
46
|
authors,
|
|
44
47
|
page: opts.page,
|
|
@@ -52,7 +55,7 @@ export const registerAuditLogCommand = (program, services) => {
|
|
|
52
55
|
id: e.id ?? "",
|
|
53
56
|
timestamp: e.timestamp ?? "",
|
|
54
57
|
action: e.action ?? "",
|
|
55
|
-
author: e.authorName ?? e.authorId ?? "",
|
|
58
|
+
author: e.userName ?? e.userEmail ?? e.userId ?? e.authorName ?? e.authorId ?? "",
|
|
56
59
|
entityType: e.entityType ?? "",
|
|
57
60
|
entityId: e.entityId ?? "",
|
|
58
61
|
};
|