@apet97/clockify-cli-115 0.1.1 → 0.3.1
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 +81 -21
- package/dist/commands/doctor.js +7 -11
- package/dist/commands/entries.js +3 -4
- package/dist/commands/expenses.js +7 -16
- package/dist/commands/invoices.js +3 -4
- package/dist/commands/leaf-command.js +45 -0
- package/dist/commands/log.js +2 -2
- package/dist/commands/projects.js +6 -10
- package/dist/commands/reports.js +45 -13
- package/dist/commands/scheduling.js +3 -4
- package/dist/commands/sharedReports.js +209 -39
- package/dist/commands/start.js +2 -2
- package/dist/commands/status.js +2 -2
- package/dist/commands/stop.js +2 -2
- package/dist/commands/tags.js +6 -5
- 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/generated/version.js +1 -0
- package/dist/index.js +11 -13
- package/package.json +16 -15
package/dist/commands/tasks.js
CHANGED
|
@@ -1,11 +1,89 @@
|
|
|
1
|
-
import { wireBody } from "clockify-sdk-ts-115/requests";
|
|
2
1
|
import { printObject, printRecords } from "../output.js";
|
|
3
2
|
import { printReceipt } from "../receipt.js";
|
|
4
3
|
import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
|
|
4
|
+
import { leafCommand } from "./leaf-command.js";
|
|
5
|
+
function requireTaskName(value, source) {
|
|
6
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
7
|
+
throw new Error(`${source} is missing the required task name; refusing to mutate.`);
|
|
8
|
+
}
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
function taskStatus(value, source) {
|
|
12
|
+
const status = String(value).toUpperCase();
|
|
13
|
+
if (status !== "ACTIVE" && status !== "DONE") {
|
|
14
|
+
throw new Error(`${source} has unknown task status: ${String(value)}`);
|
|
15
|
+
}
|
|
16
|
+
return status;
|
|
17
|
+
}
|
|
18
|
+
function stringList(value, field) {
|
|
19
|
+
if (value === undefined)
|
|
20
|
+
return undefined;
|
|
21
|
+
if (!Array.isArray(value) || value.some((item) => typeof item !== "string")) {
|
|
22
|
+
throw new Error(`Current task has invalid ${field}; refusing to mutate.`);
|
|
23
|
+
}
|
|
24
|
+
return [...value];
|
|
25
|
+
}
|
|
26
|
+
function optionalTaskString(value, field) {
|
|
27
|
+
if (value === undefined)
|
|
28
|
+
return undefined;
|
|
29
|
+
if (typeof value !== "string") {
|
|
30
|
+
throw new Error(`Current task has invalid ${field}; refusing to mutate.`);
|
|
31
|
+
}
|
|
32
|
+
return value;
|
|
33
|
+
}
|
|
34
|
+
function optionalNullableTaskString(value, field) {
|
|
35
|
+
if (value === null)
|
|
36
|
+
return undefined;
|
|
37
|
+
return optionalTaskString(value, field);
|
|
38
|
+
}
|
|
39
|
+
function requiredTaskBoolean(value, field) {
|
|
40
|
+
if (typeof value !== "boolean") {
|
|
41
|
+
throw new Error(`Current task has invalid or missing ${field}; refusing to mutate.`);
|
|
42
|
+
}
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
function optionalTaskInteger(value, field) {
|
|
46
|
+
if (value === undefined)
|
|
47
|
+
return undefined;
|
|
48
|
+
if (typeof value !== "number" || !Number.isFinite(value) || !Number.isInteger(value)) {
|
|
49
|
+
throw new Error(`Current task has invalid ${field}; refusing to mutate.`);
|
|
50
|
+
}
|
|
51
|
+
return value;
|
|
52
|
+
}
|
|
53
|
+
function sameStringList(left, right) {
|
|
54
|
+
return left !== undefined && left.length === right.length && left.every((item, i) => item === right[i]);
|
|
55
|
+
}
|
|
56
|
+
function reconstructTaskBody(current, suppliedName) {
|
|
57
|
+
const body = {
|
|
58
|
+
name: suppliedName !== undefined
|
|
59
|
+
? requireTaskName(suppliedName, "Task update request")
|
|
60
|
+
: requireTaskName(current.name, "Current task"),
|
|
61
|
+
};
|
|
62
|
+
const assigneeId = optionalNullableTaskString(current.assigneeId, "assigneeId");
|
|
63
|
+
if (assigneeId !== undefined)
|
|
64
|
+
body.assigneeId = assigneeId;
|
|
65
|
+
const assigneeIds = stringList(current.assigneeIds, "assigneeIds");
|
|
66
|
+
if (assigneeIds !== undefined)
|
|
67
|
+
body.assigneeIds = assigneeIds;
|
|
68
|
+
body.billable = requiredTaskBoolean(current.billable, "billable");
|
|
69
|
+
const budgetEstimate = optionalTaskInteger(current.budgetEstimate, "budgetEstimate");
|
|
70
|
+
if (budgetEstimate !== undefined)
|
|
71
|
+
body.budgetEstimate = budgetEstimate;
|
|
72
|
+
const estimate = optionalTaskString(current.estimate, "estimate");
|
|
73
|
+
if (estimate !== undefined)
|
|
74
|
+
body.estimate = estimate;
|
|
75
|
+
if (current.status === undefined) {
|
|
76
|
+
throw new Error("Current task is missing the required status; refusing to mutate.");
|
|
77
|
+
}
|
|
78
|
+
body.status = taskStatus(current.status, "Current task");
|
|
79
|
+
const userGroupIds = stringList(current.userGroupIds, "userGroupIds");
|
|
80
|
+
if (userGroupIds !== undefined)
|
|
81
|
+
body.userGroupIds = userGroupIds;
|
|
82
|
+
return body;
|
|
83
|
+
}
|
|
5
84
|
export const registerTasksCommand = (program, services) => {
|
|
6
85
|
const tasks = program.command("tasks").description("Manage tasks.");
|
|
7
|
-
tasks
|
|
8
|
-
.command("list")
|
|
86
|
+
leafCommand(tasks, "list", "read")
|
|
9
87
|
.argument("<projectId>", "Project ID.")
|
|
10
88
|
.description("List tasks for a project.")
|
|
11
89
|
.option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
|
|
@@ -33,8 +111,7 @@ export const registerTasksCommand = (program, services) => {
|
|
|
33
111
|
});
|
|
34
112
|
printRecords(rows, output);
|
|
35
113
|
});
|
|
36
|
-
tasks
|
|
37
|
-
.command("create")
|
|
114
|
+
leafCommand(tasks, "create", "write")
|
|
38
115
|
.argument("<projectId>", "Project ID.")
|
|
39
116
|
.argument("<name>", "Task name.")
|
|
40
117
|
.option("--billable", "Mark as billable.")
|
|
@@ -43,18 +120,19 @@ export const registerTasksCommand = (program, services) => {
|
|
|
43
120
|
.description("Create a task under a project.")
|
|
44
121
|
.action(async function (projectId, name, opts) {
|
|
45
122
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
123
|
+
requireTaskName(name, "Task create request");
|
|
46
124
|
const body = { name };
|
|
47
125
|
if (opts.billable !== undefined)
|
|
48
126
|
body.billable = opts.billable;
|
|
49
|
-
if (opts.estimate)
|
|
127
|
+
if (opts.estimate !== undefined)
|
|
50
128
|
body.estimate = opts.estimate;
|
|
51
|
-
if (Array.isArray(opts.assignee)
|
|
129
|
+
if (Array.isArray(opts.assignee))
|
|
52
130
|
body.assigneeIds = opts.assignee;
|
|
53
|
-
const req =
|
|
131
|
+
const req = {
|
|
54
132
|
workspaceId,
|
|
55
133
|
projectId,
|
|
56
134
|
body,
|
|
57
|
-
}
|
|
135
|
+
};
|
|
58
136
|
const created = (await client.tasks.create(req));
|
|
59
137
|
const data = { id: created.id ?? "", name: created.name ?? name };
|
|
60
138
|
printReceipt({
|
|
@@ -72,8 +150,7 @@ export const registerTasksCommand = (program, services) => {
|
|
|
72
150
|
],
|
|
73
151
|
}, output);
|
|
74
152
|
});
|
|
75
|
-
tasks
|
|
76
|
-
.command("get")
|
|
153
|
+
leafCommand(tasks, "get", "read")
|
|
77
154
|
.argument("<projectId>", "Project ID.")
|
|
78
155
|
.argument("<id>", "Task ID.")
|
|
79
156
|
.description("Get one task by project ID and task ID.")
|
|
@@ -82,11 +159,10 @@ export const registerTasksCommand = (program, services) => {
|
|
|
82
159
|
const task = await client.tasks.get({ workspaceId, projectId, taskId: id });
|
|
83
160
|
printObject(task, output);
|
|
84
161
|
});
|
|
85
|
-
tasks
|
|
86
|
-
.command("update")
|
|
162
|
+
leafCommand(tasks, "update", "write")
|
|
87
163
|
.argument("<projectId>", "Project ID.")
|
|
88
164
|
.argument("<id>", "Task ID.")
|
|
89
|
-
.option("--name <text>", "
|
|
165
|
+
.option("--name <text>", "Task name.")
|
|
90
166
|
.option("--status <status>", "ACTIVE or DONE.")
|
|
91
167
|
.option("--estimate <iso>", "ISO-8601 duration estimate (e.g. PT8H).")
|
|
92
168
|
.option("--billable", "Mark as billable.")
|
|
@@ -95,25 +171,49 @@ export const registerTasksCommand = (program, services) => {
|
|
|
95
171
|
.description("Update a task by project ID and task ID.")
|
|
96
172
|
.action(async function (projectId, id, opts) {
|
|
97
173
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
if (
|
|
174
|
+
const hasChanges = opts.name !== undefined ||
|
|
175
|
+
opts.status !== undefined ||
|
|
176
|
+
opts.estimate !== undefined ||
|
|
177
|
+
opts.billable !== undefined ||
|
|
178
|
+
opts.assignee !== undefined;
|
|
179
|
+
if (!hasChanges) {
|
|
180
|
+
throw new Error("tasks.update requires at least one task field to change.");
|
|
181
|
+
}
|
|
182
|
+
const current = (await client.tasks.get({
|
|
183
|
+
workspaceId,
|
|
184
|
+
projectId,
|
|
185
|
+
taskId: id,
|
|
186
|
+
}));
|
|
187
|
+
const body = reconstructTaskBody(current, opts.name);
|
|
188
|
+
let changed = opts.name !== undefined && opts.name !== current.name;
|
|
189
|
+
if (opts.status !== undefined) {
|
|
190
|
+
const status = taskStatus(opts.status, "Task update request");
|
|
191
|
+
changed = changed || status !== body.status;
|
|
192
|
+
body.status = status;
|
|
193
|
+
}
|
|
194
|
+
if (opts.estimate !== undefined) {
|
|
195
|
+
changed = changed || opts.estimate !== body.estimate;
|
|
104
196
|
body.estimate = opts.estimate;
|
|
105
|
-
|
|
197
|
+
}
|
|
198
|
+
if (opts.billable !== undefined) {
|
|
199
|
+
changed = changed || opts.billable !== body.billable;
|
|
106
200
|
body.billable = opts.billable;
|
|
107
|
-
|
|
201
|
+
}
|
|
202
|
+
if (Array.isArray(opts.assignee)) {
|
|
203
|
+
changed = changed || !sameStringList(body.assigneeIds, opts.assignee);
|
|
108
204
|
body.assigneeIds = opts.assignee;
|
|
109
|
-
|
|
205
|
+
}
|
|
206
|
+
if (!changed) {
|
|
207
|
+
throw new Error("tasks.update values are unchanged; refusing to mutate.");
|
|
208
|
+
}
|
|
209
|
+
const req = {
|
|
110
210
|
workspaceId,
|
|
111
211
|
projectId,
|
|
112
212
|
taskId: id,
|
|
113
213
|
body,
|
|
114
|
-
}
|
|
214
|
+
};
|
|
115
215
|
const updated = (await client.tasks.update(req));
|
|
116
|
-
const data = { id: updated.id ?? id, name: updated.name ??
|
|
216
|
+
const data = { id: updated.id ?? id, name: updated.name ?? body.name };
|
|
117
217
|
printReceipt({
|
|
118
218
|
ok: true,
|
|
119
219
|
action: "tasks.update",
|
|
@@ -129,22 +229,46 @@ export const registerTasksCommand = (program, services) => {
|
|
|
129
229
|
],
|
|
130
230
|
}, output);
|
|
131
231
|
});
|
|
132
|
-
tasks
|
|
133
|
-
.command("delete")
|
|
232
|
+
leafCommand(tasks, "delete", "destructive")
|
|
134
233
|
.argument("<projectId>", "Project ID.")
|
|
135
234
|
.argument("<id>", "Task ID.")
|
|
136
235
|
.description("Delete a task by project ID and task ID (marks DONE first; an active task cannot be deleted).")
|
|
137
236
|
.action(async function (projectId, id) {
|
|
138
237
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
139
|
-
const current = (await client.tasks.get({
|
|
140
|
-
await client.tasks.update(wireBody({
|
|
238
|
+
const current = (await client.tasks.get({
|
|
141
239
|
workspaceId,
|
|
142
240
|
projectId,
|
|
143
241
|
taskId: id,
|
|
144
|
-
name: String(current.name ?? ""),
|
|
145
|
-
status: "DONE",
|
|
146
242
|
}));
|
|
147
|
-
|
|
243
|
+
const originalBody = reconstructTaskBody(current);
|
|
244
|
+
if (originalBody.status === undefined) {
|
|
245
|
+
throw new Error("Current task is missing the required status for safe delete.");
|
|
246
|
+
}
|
|
247
|
+
const changedStatus = originalBody.status !== "DONE";
|
|
248
|
+
if (changedStatus) {
|
|
249
|
+
const doneRequest = {
|
|
250
|
+
workspaceId,
|
|
251
|
+
projectId,
|
|
252
|
+
taskId: id,
|
|
253
|
+
body: { ...originalBody, status: "DONE" },
|
|
254
|
+
};
|
|
255
|
+
await client.tasks.update(doneRequest);
|
|
256
|
+
}
|
|
257
|
+
try {
|
|
258
|
+
await client.tasks.delete({ workspaceId, projectId, taskId: id });
|
|
259
|
+
}
|
|
260
|
+
catch (error) {
|
|
261
|
+
if (changedStatus) {
|
|
262
|
+
const rollbackRequest = {
|
|
263
|
+
workspaceId,
|
|
264
|
+
projectId,
|
|
265
|
+
taskId: id,
|
|
266
|
+
body: originalBody,
|
|
267
|
+
};
|
|
268
|
+
await client.tasks.update(rollbackRequest);
|
|
269
|
+
}
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
148
272
|
printReceipt({
|
|
149
273
|
ok: true,
|
|
150
274
|
action: "tasks.delete",
|
package/dist/commands/timeoff.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { wireBody } from "clockify-sdk-ts-115/requests";
|
|
2
1
|
import { printRecords } from "../output.js";
|
|
3
2
|
import { printReceipt } from "../receipt.js";
|
|
4
3
|
import { clampPageSize, parseIntArg, resolveContext, splitList } from "./helpers.js";
|
|
4
|
+
import { leafCommand } from "./leaf-command.js";
|
|
5
5
|
export const registerTimeOffCommand = (program, services) => {
|
|
6
6
|
const timeoff = program.command("timeoff").description("Time-off requests.");
|
|
7
|
-
timeoff
|
|
8
|
-
.command("list")
|
|
7
|
+
leafCommand(timeoff, "list", "read")
|
|
9
8
|
.description("List time-off requests in the workspace.")
|
|
10
9
|
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
11
10
|
.option("--limit <n>", "Items per page (default 50, max 200).", parseIntArg, 50)
|
|
@@ -24,11 +23,17 @@ export const registerTimeOffCommand = (program, services) => {
|
|
|
24
23
|
req.start = opts.start;
|
|
25
24
|
if (opts.end)
|
|
26
25
|
req.end = opts.end;
|
|
27
|
-
if (opts.status)
|
|
28
|
-
|
|
26
|
+
if (opts.status) {
|
|
27
|
+
const statuses = splitList(opts.status);
|
|
28
|
+
const known = new Set(["PENDING", "APPROVED", "REJECTED", "ALL"]);
|
|
29
|
+
const invalid = statuses.filter((status) => !known.has(status));
|
|
30
|
+
if (invalid.length > 0)
|
|
31
|
+
throw new Error(`Unknown time-off status: ${invalid.join(", ")}`);
|
|
32
|
+
req.statuses = statuses;
|
|
33
|
+
}
|
|
29
34
|
if (opts.user)
|
|
30
35
|
req.users = splitList(opts.user);
|
|
31
|
-
const items = (await client.timeOff.list(
|
|
36
|
+
const items = (await client.timeOff.list(req));
|
|
32
37
|
const rows = items.map((raw) => {
|
|
33
38
|
const r = raw;
|
|
34
39
|
const statusValue = typeof r.status === "object" && r.status !== null
|
|
@@ -48,8 +53,7 @@ export const registerTimeOffCommand = (program, services) => {
|
|
|
48
53
|
});
|
|
49
54
|
printRecords(rows, output);
|
|
50
55
|
});
|
|
51
|
-
timeoff
|
|
52
|
-
.command("submit")
|
|
56
|
+
leafCommand(timeoff, "submit", "write")
|
|
53
57
|
.description("Submit a time-off request against a policy.")
|
|
54
58
|
.requiredOption("--policy <id>", "Time-off policy ID.")
|
|
55
59
|
.requiredOption("--start <date>", "Period start (date-only YYYY-MM-DD for DAYS-unit policies, RFC3339 for HOURS-unit).")
|
package/dist/commands/users.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { printObject, printRecords } from "../output.js";
|
|
2
2
|
import { printReceipt } from "../receipt.js";
|
|
3
3
|
import { clampPageSize, parseIntArg, resolveBaseContext, resolveContext } from "./helpers.js";
|
|
4
|
+
import { leafCommand } from "./leaf-command.js";
|
|
4
5
|
export const registerUsersCommand = (program, services) => {
|
|
5
6
|
const users = program.command("users").description("Inspect workspace users.");
|
|
6
|
-
users
|
|
7
|
-
.command("me")
|
|
7
|
+
leafCommand(users, "me", "read")
|
|
8
8
|
.description("Show the current authenticated user (the API-key owner).")
|
|
9
9
|
.action(async function () {
|
|
10
10
|
const { client, output } = await resolveBaseContext(this, services);
|
|
11
11
|
const me = await client.users.getCurrentUser();
|
|
12
12
|
printObject(me, output);
|
|
13
13
|
});
|
|
14
|
-
users
|
|
15
|
-
.command("list")
|
|
14
|
+
leafCommand(users, "list", "read")
|
|
16
15
|
.description("List members of the workspace.")
|
|
17
16
|
.option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
|
|
18
17
|
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
@@ -39,8 +38,7 @@ export const registerUsersCommand = (program, services) => {
|
|
|
39
38
|
});
|
|
40
39
|
printRecords(rows, output);
|
|
41
40
|
});
|
|
42
|
-
users
|
|
43
|
-
.command("invite")
|
|
41
|
+
leafCommand(users, "invite", "write")
|
|
44
42
|
.argument("<email>", "Email address of the user to invite.")
|
|
45
43
|
.option("--no-send-email", "Do not send the invitation email.")
|
|
46
44
|
.description("Invite (add) a user to the workspace by email.")
|
|
@@ -71,8 +69,7 @@ export const registerUsersCommand = (program, services) => {
|
|
|
71
69
|
],
|
|
72
70
|
}, output);
|
|
73
71
|
});
|
|
74
|
-
users
|
|
75
|
-
.command("update-profile")
|
|
72
|
+
leafCommand(users, "update-profile", "write")
|
|
76
73
|
.argument("<userId>", "User ID whose member profile to update.")
|
|
77
74
|
.option("--name <text>", "Display name.")
|
|
78
75
|
.option("--image-url <url>", "Profile image URL.")
|
|
@@ -1,20 +1,119 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { requestOptions } from "clockify-sdk-ts-115/request-options";
|
|
2
2
|
import { assertSafeWebhookUrl } from "clockify-sdk-ts-115/webhooks";
|
|
3
3
|
import { printRecords } from "../output.js";
|
|
4
4
|
import { printReceipt } from "../receipt.js";
|
|
5
5
|
import { resolveContext, splitList } from "./helpers.js";
|
|
6
|
+
import { leafCommand } from "./leaf-command.js";
|
|
7
|
+
const WEBHOOK_LIST_TYPES = ["WEBHOOK", "ADDON_WEBHOOK"];
|
|
8
|
+
const WEBHOOK_TRIGGER_SOURCE_TYPES = [
|
|
9
|
+
"PROJECT_ID",
|
|
10
|
+
"USER_ID",
|
|
11
|
+
"TAG_ID",
|
|
12
|
+
"TASK_ID",
|
|
13
|
+
"WORKSPACE_ID",
|
|
14
|
+
"ASSIGNMENT_ID",
|
|
15
|
+
"EXPENSE_ID",
|
|
16
|
+
];
|
|
17
|
+
const WEBHOOK_EVENT_TYPES = [
|
|
18
|
+
"NEW_TIME_ENTRY",
|
|
19
|
+
"TIME_ENTRY_UPDATED",
|
|
20
|
+
"TIME_ENTRY_DELETED",
|
|
21
|
+
"TIME_ENTRY_SPLIT",
|
|
22
|
+
"TIME_ENTRY_RESTORED",
|
|
23
|
+
"NEW_TIMER_STARTED",
|
|
24
|
+
"TIMER_STOPPED",
|
|
25
|
+
"NEW_PROJECT",
|
|
26
|
+
"PROJECT_UPDATED",
|
|
27
|
+
"PROJECT_DELETED",
|
|
28
|
+
"NEW_TASK",
|
|
29
|
+
"TASK_UPDATED",
|
|
30
|
+
"TASK_DELETED",
|
|
31
|
+
"NEW_CLIENT",
|
|
32
|
+
"CLIENT_UPDATED",
|
|
33
|
+
"CLIENT_DELETED",
|
|
34
|
+
"NEW_TAG",
|
|
35
|
+
"TAG_UPDATED",
|
|
36
|
+
"TAG_DELETED",
|
|
37
|
+
"USER_JOINED_WORKSPACE",
|
|
38
|
+
"USER_DELETED_FROM_WORKSPACE",
|
|
39
|
+
"USER_DEACTIVATED_ON_WORKSPACE",
|
|
40
|
+
"USER_ACTIVATED_ON_WORKSPACE",
|
|
41
|
+
"USER_EMAIL_CHANGED",
|
|
42
|
+
"USER_UPDATED",
|
|
43
|
+
"USERS_INVITED_TO_WORKSPACE",
|
|
44
|
+
"LIMITED_USERS_ADDED_TO_WORKSPACE",
|
|
45
|
+
"NEW_INVOICE",
|
|
46
|
+
"INVOICE_UPDATED",
|
|
47
|
+
"NEW_APPROVAL_REQUEST",
|
|
48
|
+
"APPROVAL_REQUEST_STATUS_UPDATED",
|
|
49
|
+
"TIME_OFF_REQUESTED",
|
|
50
|
+
"TIME_OFF_REQUEST_UPDATED",
|
|
51
|
+
"TIME_OFF_REQUEST_APPROVED",
|
|
52
|
+
"TIME_OFF_REQUEST_REJECTED",
|
|
53
|
+
"TIME_OFF_REQUEST_STARTED",
|
|
54
|
+
"TIME_OFF_REQUEST_WITHDRAWN",
|
|
55
|
+
"BALANCE_UPDATED",
|
|
56
|
+
"EXPENSE_CREATED",
|
|
57
|
+
"EXPENSE_UPDATED",
|
|
58
|
+
"EXPENSE_DELETED",
|
|
59
|
+
"EXPENSE_RESTORED",
|
|
60
|
+
"ASSIGNMENT_CREATED",
|
|
61
|
+
"ASSIGNMENT_UPDATED",
|
|
62
|
+
"ASSIGNMENT_DELETED",
|
|
63
|
+
"ASSIGNMENT_PUBLISHED",
|
|
64
|
+
"USER_GROUP_CREATED",
|
|
65
|
+
"USER_GROUP_UPDATED",
|
|
66
|
+
"USER_GROUP_DELETED",
|
|
67
|
+
"COST_RATE_UPDATED",
|
|
68
|
+
"BILLABLE_RATE_UPDATED",
|
|
69
|
+
];
|
|
70
|
+
const USER_ID_TRIGGER_EVENTS = new Set([
|
|
71
|
+
"USER_EMAIL_CHANGED",
|
|
72
|
+
"USER_UPDATED",
|
|
73
|
+
]);
|
|
74
|
+
const webhookEventsExhaustive = true;
|
|
75
|
+
void webhookEventsExhaustive;
|
|
76
|
+
function nonEmptyString(value, field) {
|
|
77
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
78
|
+
throw new Error(`webhooks.create: ${field} must be a non-empty string.`);
|
|
79
|
+
}
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
function webhookEvent(value) {
|
|
83
|
+
const event = String(value).toUpperCase();
|
|
84
|
+
if (!WEBHOOK_EVENT_TYPES.includes(event)) {
|
|
85
|
+
throw new Error(`Unknown webhook event: ${String(value)}`);
|
|
86
|
+
}
|
|
87
|
+
return event;
|
|
88
|
+
}
|
|
89
|
+
function webhookTriggerSourceType(value) {
|
|
90
|
+
const raw = value ?? "WORKSPACE_ID";
|
|
91
|
+
if (typeof raw !== "string") {
|
|
92
|
+
throw new Error("Unknown trigger source type: expected a string.");
|
|
93
|
+
}
|
|
94
|
+
const type = raw.toUpperCase();
|
|
95
|
+
if (!WEBHOOK_TRIGGER_SOURCE_TYPES.includes(type)) {
|
|
96
|
+
throw new Error(`Unknown trigger source type: ${raw}`);
|
|
97
|
+
}
|
|
98
|
+
return type;
|
|
99
|
+
}
|
|
6
100
|
export const registerWebhooksCommand = (program, services) => {
|
|
7
101
|
const webhooks = program.command("webhooks").description("Manage outbound webhooks.");
|
|
8
|
-
webhooks
|
|
9
|
-
.command("list")
|
|
102
|
+
leafCommand(webhooks, "list", "read")
|
|
10
103
|
.description("List webhooks in the workspace.")
|
|
11
104
|
.option("--type <type>", "Filter by webhook type (e.g. WEBHOOK, ADDON_WEBHOOK).")
|
|
12
105
|
.action(async function (opts) {
|
|
13
106
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
14
|
-
|
|
15
|
-
if (opts.type)
|
|
16
|
-
|
|
17
|
-
|
|
107
|
+
let type;
|
|
108
|
+
if (opts.type) {
|
|
109
|
+
const candidate = String(opts.type).toUpperCase();
|
|
110
|
+
if (!WEBHOOK_LIST_TYPES.includes(candidate)) {
|
|
111
|
+
throw new Error(`Unknown webhook type: ${opts.type}`);
|
|
112
|
+
}
|
|
113
|
+
type = candidate;
|
|
114
|
+
}
|
|
115
|
+
const options = type ? requestOptions({ queryParams: { type } }) : undefined;
|
|
116
|
+
const response = (await client.webhooks.list({ workspaceId }, options));
|
|
18
117
|
const items = Array.isArray(response) ? response : (response.webhooks ?? []);
|
|
19
118
|
const rows = items.map((raw) => {
|
|
20
119
|
const w = raw;
|
|
@@ -29,8 +128,7 @@ export const registerWebhooksCommand = (program, services) => {
|
|
|
29
128
|
});
|
|
30
129
|
printRecords(rows, output);
|
|
31
130
|
});
|
|
32
|
-
webhooks
|
|
33
|
-
.command("create")
|
|
131
|
+
leafCommand(webhooks, "create", "write")
|
|
34
132
|
.description("Create a webhook subscription.")
|
|
35
133
|
.requiredOption("--name <text>", "Webhook label.")
|
|
36
134
|
.requiredOption("--url <url>", "Target URL (HTTPS).")
|
|
@@ -39,26 +137,36 @@ export const registerWebhooksCommand = (program, services) => {
|
|
|
39
137
|
.option("--trigger-source <ids>", "Comma-separated trigger source IDs (required when --trigger-source-type is set).")
|
|
40
138
|
.action(async function (opts) {
|
|
41
139
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
140
|
+
const name = nonEmptyString(opts.name, "name");
|
|
141
|
+
const url = nonEmptyString(opts.url, "url");
|
|
42
142
|
try {
|
|
43
|
-
assertSafeWebhookUrl(
|
|
143
|
+
assertSafeWebhookUrl(url);
|
|
44
144
|
}
|
|
45
145
|
catch (err) {
|
|
46
146
|
throw new Error(`webhooks.create: ${err instanceof Error ? err.message : String(err)}`);
|
|
47
147
|
}
|
|
148
|
+
const event = webhookEvent(opts.event);
|
|
149
|
+
const triggerSourceType = webhookTriggerSourceType(opts.triggerSourceType);
|
|
150
|
+
if (USER_ID_TRIGGER_EVENTS.has(event) && triggerSourceType !== "USER_ID") {
|
|
151
|
+
throw new Error(`webhooks.create: ${event} requires USER_ID trigger sources.`);
|
|
152
|
+
}
|
|
153
|
+
const triggerSource = triggerSourceType === "WORKSPACE_ID"
|
|
154
|
+
? [workspaceId]
|
|
155
|
+
: opts.triggerSource
|
|
156
|
+
? splitList(String(opts.triggerSource))
|
|
157
|
+
: [];
|
|
158
|
+
if (triggerSource.length === 0) {
|
|
159
|
+
throw new Error(`webhooks.create: trigger source is required for ${triggerSourceType}.`);
|
|
160
|
+
}
|
|
48
161
|
const body = {
|
|
49
|
-
name
|
|
50
|
-
url
|
|
51
|
-
webhookEvent:
|
|
162
|
+
name,
|
|
163
|
+
url,
|
|
164
|
+
webhookEvent: event,
|
|
165
|
+
triggerSourceType,
|
|
166
|
+
triggerSource,
|
|
52
167
|
};
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (opts.triggerSource) {
|
|
56
|
-
body.triggerSource = splitList(String(opts.triggerSource));
|
|
57
|
-
}
|
|
58
|
-
const created = (await client.webhooks.create(wireBody({
|
|
59
|
-
workspaceId,
|
|
60
|
-
body,
|
|
61
|
-
})));
|
|
168
|
+
const request = { workspaceId, body };
|
|
169
|
+
const created = (await client.webhooks.create(request));
|
|
62
170
|
const data = {
|
|
63
171
|
id: created.id ?? "",
|
|
64
172
|
name: created.name ?? "",
|
|
@@ -81,8 +189,7 @@ export const registerWebhooksCommand = (program, services) => {
|
|
|
81
189
|
],
|
|
82
190
|
}, output);
|
|
83
191
|
});
|
|
84
|
-
webhooks
|
|
85
|
-
.command("delete")
|
|
192
|
+
leafCommand(webhooks, "delete", "destructive")
|
|
86
193
|
.argument("<id>", "Webhook ID.")
|
|
87
194
|
.description("Delete a webhook subscription.")
|
|
88
195
|
.action(async function (id) {
|
package/dist/config.js
CHANGED
|
@@ -3,7 +3,7 @@ import { homedir } from "node:os";
|
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
export function loadConfig(flags = {}, env = process.env) {
|
|
5
5
|
const file = loadRcFile(env);
|
|
6
|
-
const apiKey = firstPresent(
|
|
6
|
+
const apiKey = firstPresent(env.CLOCKIFY_API_KEY);
|
|
7
7
|
const workspaceId = firstPresent(flags.workspace, env.CLOCKIFY_WORKSPACE_ID, file.workspaceId);
|
|
8
8
|
const baseUrl = firstPresent(flags.baseUrl, env.CLOCKIFY_BASE_URL, file.baseUrl);
|
|
9
9
|
return {
|
|
@@ -17,7 +17,7 @@ function firstPresent(...values) {
|
|
|
17
17
|
}
|
|
18
18
|
export function requireApiKey(config) {
|
|
19
19
|
if (!config.apiKey) {
|
|
20
|
-
throw new Error("Clockify API key not set.
|
|
20
|
+
throw new Error("Clockify API key not set. Set CLOCKIFY_API_KEY in the process environment.");
|
|
21
21
|
}
|
|
22
22
|
return config.apiKey;
|
|
23
23
|
}
|
|
@@ -37,9 +37,10 @@ function loadRcFile(env) {
|
|
|
37
37
|
try {
|
|
38
38
|
const raw = readFileSync(path, "utf8");
|
|
39
39
|
const parsed = JSON.parse(raw);
|
|
40
|
+
if (Object.prototype.hasOwnProperty.call(parsed, "apiKey")) {
|
|
41
|
+
throw new Error("legacy rc-file secret detected: remove apiKey from the rc file and set CLOCKIFY_API_KEY in the process environment");
|
|
42
|
+
}
|
|
40
43
|
const out = {};
|
|
41
|
-
if (typeof parsed.apiKey === "string")
|
|
42
|
-
out.apiKey = parsed.apiKey;
|
|
43
44
|
if (typeof parsed.workspaceId === "string")
|
|
44
45
|
out.workspaceId = parsed.workspaceId;
|
|
45
46
|
if (typeof parsed.baseUrl === "string")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PACKAGE_VERSION = "0.3.1";
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,7 @@ import { registerDoctorCommand } from "./commands/doctor.js";
|
|
|
8
8
|
import { registerEntriesCommand } from "./commands/entries.js";
|
|
9
9
|
import { registerExpensesCommand } from "./commands/expenses.js";
|
|
10
10
|
import { registerInvoicesCommand } from "./commands/invoices.js";
|
|
11
|
+
import { leafCommand } from "./commands/leaf-command.js";
|
|
11
12
|
import { registerLogCommand } from "./commands/log.js";
|
|
12
13
|
import { registerProjectsCommand } from "./commands/projects.js";
|
|
13
14
|
import { registerReportsCommand } from "./commands/reports.js";
|
|
@@ -23,14 +24,18 @@ import { registerUsersCommand } from "./commands/users.js";
|
|
|
23
24
|
import { registerWebhooksCommand } from "./commands/webhooks.js";
|
|
24
25
|
import { parseCompletionShell, renderCompletion } from "./completions.js";
|
|
25
26
|
import { loadConfig } from "./config.js";
|
|
27
|
+
import { PACKAGE_VERSION } from "./generated/version.js";
|
|
26
28
|
import { printError } from "./output.js";
|
|
27
|
-
export
|
|
29
|
+
export const defaultServices = {
|
|
30
|
+
loadConfig,
|
|
31
|
+
buildClient,
|
|
32
|
+
};
|
|
33
|
+
export function buildProgram(services = defaultServices) {
|
|
28
34
|
const program = new Command();
|
|
29
35
|
program
|
|
30
36
|
.name("clockify115")
|
|
31
37
|
.description("Clockify CLI from @apet97/clockify-cli-115, built on clockify-sdk-ts-115.")
|
|
32
|
-
.version(
|
|
33
|
-
.option("--api-key <key>", "Clockify personal API key (or CLOCKIFY_API_KEY env var).")
|
|
38
|
+
.version(PACKAGE_VERSION)
|
|
34
39
|
.option("--workspace <id>", "Clockify workspace ID (or CLOCKIFY_WORKSPACE_ID env var).")
|
|
35
40
|
.option("--base-url <url>", "Override Clockify API base URL (or CLOCKIFY_BASE_URL env var). Only a Clockify host or a loopback host is accepted; arbitrary hosts are rejected.")
|
|
36
41
|
.option("--json", "Emit machine-readable JSON instead of human-friendly tables.", false)
|
|
@@ -39,10 +44,6 @@ export function buildProgram() {
|
|
|
39
44
|
.option("--select <path>", "Select a dot-path before printing JSON or NDJSON.")
|
|
40
45
|
.option("--no-color", "Disable ANSI color output.")
|
|
41
46
|
.showHelpAfterError(true);
|
|
42
|
-
const services = {
|
|
43
|
-
loadConfig,
|
|
44
|
-
buildClient,
|
|
45
|
-
};
|
|
46
47
|
registerApiCommand(program, services);
|
|
47
48
|
registerStatusCommand(program, services);
|
|
48
49
|
registerDoctorCommand(program, services);
|
|
@@ -63,8 +64,7 @@ export function buildProgram() {
|
|
|
63
64
|
registerReportsCommand(program, services);
|
|
64
65
|
registerSharedReportsCommand(program, services);
|
|
65
66
|
registerUsersCommand(program, services);
|
|
66
|
-
program
|
|
67
|
-
.command("completion")
|
|
67
|
+
leafCommand(program, "completion", "read")
|
|
68
68
|
.argument("[shell]", "Shell to generate completion for: zsh, bash, or fish.", "zsh")
|
|
69
69
|
.description("Print shell completion script for zsh, bash, or fish.")
|
|
70
70
|
.action((shell) => {
|
|
@@ -111,16 +111,14 @@ function resolveMode(output, json) {
|
|
|
111
111
|
export function globalFlags(program) {
|
|
112
112
|
const opts = program.opts();
|
|
113
113
|
const out = {};
|
|
114
|
-
if (opts.apiKey)
|
|
115
|
-
out.apiKey = opts.apiKey;
|
|
116
114
|
if (opts.workspace)
|
|
117
115
|
out.workspace = opts.workspace;
|
|
118
116
|
if (opts.baseUrl)
|
|
119
117
|
out.baseUrl = opts.baseUrl;
|
|
120
118
|
return out;
|
|
121
119
|
}
|
|
122
|
-
export async function main(argv) {
|
|
123
|
-
const program = buildProgram();
|
|
120
|
+
export async function main(argv, services = defaultServices) {
|
|
121
|
+
const program = buildProgram(services);
|
|
124
122
|
const applyExitOverride = (cmd) => {
|
|
125
123
|
cmd.exitOverride();
|
|
126
124
|
for (const sub of cmd.commands)
|