@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/tags.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { tagUpdate } from "clockify-sdk-ts-115/updates";
|
|
2
|
+
import { UsageError } from "../failure.js";
|
|
1
3
|
import { printObject, printRecords } from "../output.js";
|
|
2
4
|
import { printReceipt } from "../receipt.js";
|
|
5
|
+
import { dispatchedWrite } from "../write-outcome.js";
|
|
3
6
|
import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
|
|
4
7
|
import { leafCommand } from "./leaf-command.js";
|
|
5
8
|
export const registerTagsCommand = (program, services) => {
|
|
@@ -42,7 +45,7 @@ export const registerTagsCommand = (program, services) => {
|
|
|
42
45
|
.action(async function (name) {
|
|
43
46
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
44
47
|
const req = { workspaceId, body: { name } };
|
|
45
|
-
const created = (await client.tags.create(req));
|
|
48
|
+
const created = (await dispatchedWrite(this, client.tags.create(req)));
|
|
46
49
|
const data = { id: created.id ?? "", name: created.name ?? "" };
|
|
47
50
|
printReceipt({
|
|
48
51
|
ok: true,
|
|
@@ -76,18 +79,15 @@ export const registerTagsCommand = (program, services) => {
|
|
|
76
79
|
" $ clk115 tags update tag_123 --archived\n")
|
|
77
80
|
.action(async function (id, opts) {
|
|
78
81
|
if (!opts.name && opts.archived === undefined) {
|
|
79
|
-
throw new
|
|
82
|
+
throw new UsageError("tags.update needs a change: provide at least one tag field.");
|
|
80
83
|
}
|
|
81
84
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const body =
|
|
86
|
-
name: opts.name ? opts.name : (current.name ?? ""),
|
|
87
|
-
archived: opts.archived ?? current.archived ?? false,
|
|
88
|
-
};
|
|
85
|
+
const patch = { name: opts.name || undefined, archived: opts.archived };
|
|
86
|
+
const complete = patch.name !== undefined && patch.archived !== undefined;
|
|
87
|
+
const current = complete ? {} : await client.tags.get({ workspaceId, tagId: id });
|
|
88
|
+
const body = tagUpdate.body(current, patch);
|
|
89
89
|
const req = { workspaceId, tagId: id, body };
|
|
90
|
-
const updated = (await client.tags.update(req));
|
|
90
|
+
const updated = (await dispatchedWrite(this, client.tags.update(req)));
|
|
91
91
|
const data = { id: updated.id ?? id, name: updated.name ?? "" };
|
|
92
92
|
printReceipt({
|
|
93
93
|
ok: true,
|
|
@@ -105,7 +105,7 @@ export const registerTagsCommand = (program, services) => {
|
|
|
105
105
|
.addHelpText("after", "\nExamples:\n" + " $ clk115 tags delete tag_123\n")
|
|
106
106
|
.action(async function (id) {
|
|
107
107
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
108
|
-
await client.tags.delete({ workspaceId, tagId: id });
|
|
108
|
+
await dispatchedWrite(this, client.tags.delete({ workspaceId, tagId: id }));
|
|
109
109
|
printReceipt({
|
|
110
110
|
ok: true,
|
|
111
111
|
action: "tags.delete",
|
package/dist/commands/tasks.js
CHANGED
|
@@ -1,86 +1,17 @@
|
|
|
1
|
+
import { taskUpdate } from "clockify-sdk-ts-115/updates";
|
|
2
|
+
import { PartialDeleteError, UsageError } from "../failure.js";
|
|
1
3
|
import { printObject, printRecords } from "../output.js";
|
|
2
4
|
import { printReceipt } from "../receipt.js";
|
|
5
|
+
import { dispatchedWrite } from "../write-outcome.js";
|
|
3
6
|
import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
|
|
4
7
|
import { leafCommand } from "./leaf-command.js";
|
|
5
|
-
function
|
|
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) {
|
|
8
|
+
function taskStatus(value) {
|
|
12
9
|
const status = String(value).toUpperCase();
|
|
13
10
|
if (status !== "ACTIVE" && status !== "DONE") {
|
|
14
|
-
throw new
|
|
11
|
+
throw new UsageError(`Task update request has unknown task status: ${String(value)}; provide ACTIVE or DONE`);
|
|
15
12
|
}
|
|
16
13
|
return status;
|
|
17
14
|
}
|
|
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
|
-
}
|
|
84
15
|
export const registerTasksCommand = (program, services) => {
|
|
85
16
|
const tasks = program.command("tasks").description("Manage tasks.");
|
|
86
17
|
leafCommand(tasks, "list", "read")
|
|
@@ -126,7 +57,8 @@ export const registerTasksCommand = (program, services) => {
|
|
|
126
57
|
" $ clk115 tasks create project_123 Design --billable --estimate PT8H\n")
|
|
127
58
|
.action(async function (projectId, name, opts) {
|
|
128
59
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
129
|
-
|
|
60
|
+
if (name.trim() === "")
|
|
61
|
+
throw new Error("Task create request is missing the required task name.");
|
|
130
62
|
const body = { name };
|
|
131
63
|
if (opts.billable !== undefined)
|
|
132
64
|
body.billable = opts.billable;
|
|
@@ -139,7 +71,7 @@ export const registerTasksCommand = (program, services) => {
|
|
|
139
71
|
projectId,
|
|
140
72
|
body,
|
|
141
73
|
};
|
|
142
|
-
const created = (await client.tasks.create(req));
|
|
74
|
+
const created = (await dispatchedWrite(this, client.tasks.create(req)));
|
|
143
75
|
const data = { id: created.id ?? "", name: created.name ?? name };
|
|
144
76
|
printReceipt({
|
|
145
77
|
ok: true,
|
|
@@ -180,40 +112,25 @@ export const registerTasksCommand = (program, services) => {
|
|
|
180
112
|
" $ clk115 tasks update project_123 task_456 --status DONE\n" +
|
|
181
113
|
" $ clk115 tasks update project_123 task_456 --name \"New name\"\n")
|
|
182
114
|
.action(async function (projectId, id, opts) {
|
|
183
|
-
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
184
115
|
const hasChanges = opts.name !== undefined ||
|
|
185
116
|
opts.status !== undefined ||
|
|
186
117
|
opts.estimate !== undefined ||
|
|
187
118
|
opts.billable !== undefined ||
|
|
188
119
|
opts.assignee !== undefined;
|
|
189
120
|
if (!hasChanges) {
|
|
190
|
-
throw new
|
|
191
|
-
}
|
|
192
|
-
const current = (await client.tasks.get({
|
|
193
|
-
workspaceId,
|
|
194
|
-
projectId,
|
|
195
|
-
taskId: id,
|
|
196
|
-
}));
|
|
197
|
-
const body = reconstructTaskBody(current, opts.name);
|
|
198
|
-
let changed = opts.name !== undefined && opts.name !== current.name;
|
|
199
|
-
if (opts.status !== undefined) {
|
|
200
|
-
const status = taskStatus(opts.status, "Task update request");
|
|
201
|
-
changed = changed || status !== body.status;
|
|
202
|
-
body.status = status;
|
|
203
|
-
}
|
|
204
|
-
if (opts.estimate !== undefined) {
|
|
205
|
-
changed = changed || opts.estimate !== body.estimate;
|
|
206
|
-
body.estimate = opts.estimate;
|
|
207
|
-
}
|
|
208
|
-
if (opts.billable !== undefined) {
|
|
209
|
-
changed = changed || opts.billable !== body.billable;
|
|
210
|
-
body.billable = opts.billable;
|
|
211
|
-
}
|
|
212
|
-
if (Array.isArray(opts.assignee)) {
|
|
213
|
-
changed = changed || !sameStringList(body.assigneeIds, opts.assignee);
|
|
214
|
-
body.assigneeIds = opts.assignee;
|
|
121
|
+
throw new UsageError("tasks.update needs a change: provide at least one task field.");
|
|
215
122
|
}
|
|
216
|
-
|
|
123
|
+
const patch = {
|
|
124
|
+
name: opts.name,
|
|
125
|
+
estimate: opts.estimate,
|
|
126
|
+
billable: opts.billable,
|
|
127
|
+
assigneeIds: opts.assignee,
|
|
128
|
+
...(opts.status === undefined ? {} : { status: taskStatus(opts.status) }),
|
|
129
|
+
};
|
|
130
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
131
|
+
const current = await client.tasks.get({ workspaceId, projectId, taskId: id });
|
|
132
|
+
const body = taskUpdate.body(current, patch);
|
|
133
|
+
if (taskUpdate.changed(current, patch).length === 0) {
|
|
217
134
|
throw new Error("tasks.update values are unchanged; provide a different value.");
|
|
218
135
|
}
|
|
219
136
|
const req = {
|
|
@@ -222,7 +139,7 @@ export const registerTasksCommand = (program, services) => {
|
|
|
222
139
|
taskId: id,
|
|
223
140
|
body,
|
|
224
141
|
};
|
|
225
|
-
const updated = (await client.tasks.update(req));
|
|
142
|
+
const updated = (await dispatchedWrite(this, client.tasks.update(req)));
|
|
226
143
|
const data = { id: updated.id ?? id, name: updated.name ?? body.name };
|
|
227
144
|
printReceipt({
|
|
228
145
|
ok: true,
|
|
@@ -246,41 +163,18 @@ export const registerTasksCommand = (program, services) => {
|
|
|
246
163
|
.addHelpText("after", "\nExamples:\n" + " $ clk115 tasks delete project_123 task_456\n")
|
|
247
164
|
.action(async function (projectId, id) {
|
|
248
165
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
249
|
-
const current =
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
taskId: id,
|
|
253
|
-
}));
|
|
254
|
-
const originalBody = reconstructTaskBody(current);
|
|
255
|
-
if (originalBody.status === undefined) {
|
|
256
|
-
throw new Error("Current task is missing the required status for safe delete.");
|
|
257
|
-
}
|
|
258
|
-
const changedStatus = originalBody.status !== "DONE";
|
|
166
|
+
const current = await client.tasks.get({ workspaceId, projectId, taskId: id });
|
|
167
|
+
const changedStatus = taskUpdate.changed(current, { status: "DONE" }).length > 0;
|
|
168
|
+
const body = taskUpdate.body(current, { status: "DONE" });
|
|
259
169
|
if (changedStatus) {
|
|
260
|
-
|
|
261
|
-
workspaceId,
|
|
262
|
-
projectId,
|
|
263
|
-
taskId: id,
|
|
264
|
-
body: { ...originalBody, status: "DONE" },
|
|
265
|
-
};
|
|
266
|
-
await client.tasks.update(doneRequest);
|
|
170
|
+
await dispatchedWrite(this, client.tasks.update({ workspaceId, projectId, taskId: id, body }));
|
|
267
171
|
}
|
|
268
172
|
try {
|
|
269
|
-
await client.tasks.delete({ workspaceId, projectId, taskId: id });
|
|
173
|
+
await dispatchedWrite(this, client.tasks.delete({ workspaceId, projectId, taskId: id }));
|
|
270
174
|
}
|
|
271
175
|
catch (error) {
|
|
272
176
|
if (changedStatus) {
|
|
273
|
-
|
|
274
|
-
workspaceId,
|
|
275
|
-
projectId,
|
|
276
|
-
taskId: id,
|
|
277
|
-
body: originalBody,
|
|
278
|
-
};
|
|
279
|
-
try {
|
|
280
|
-
await client.tasks.update(rollbackRequest);
|
|
281
|
-
}
|
|
282
|
-
catch {
|
|
283
|
-
}
|
|
177
|
+
throw new PartialDeleteError(error, "marked_done", `clk115 tasks get ${projectId} ${id} --json`);
|
|
284
178
|
}
|
|
285
179
|
throw error;
|
|
286
180
|
}
|
package/dist/commands/timeoff.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { UsageError } from "../failure.js";
|
|
1
2
|
import { printRecords } from "../output.js";
|
|
2
3
|
import { printReceipt } from "../receipt.js";
|
|
4
|
+
import { dispatchedWrite } from "../write-outcome.js";
|
|
3
5
|
import { registerBalanceAssignmentCommands } from "./balanceAssignment.js";
|
|
4
6
|
import { clampPageSize, parseIntArg, promoteDateBoundary, requireDateOrRfc3339, requireRfc3339Timestamp, resolveContext, splitList, } from "./helpers.js";
|
|
5
7
|
import { leafCommand } from "./leaf-command.js";
|
|
@@ -18,24 +20,29 @@ export const registerTimeOffCommand = (program, services) => {
|
|
|
18
20
|
.option("--status <statuses>", "Comma-separated statuses (PENDING, APPROVED, REJECTED, ALL).")
|
|
19
21
|
.option("--user <ids>", "Comma-separated user IDs to scope the search.")
|
|
20
22
|
.action(async function (opts) {
|
|
23
|
+
const start = opts.start ? promoteDateBoundary(opts.start, "start", "start") : undefined;
|
|
24
|
+
const end = opts.end ? promoteDateBoundary(opts.end, "end", "end") : undefined;
|
|
25
|
+
const statuses = opts.status
|
|
26
|
+
? splitList(opts.status).map((s) => s.toUpperCase())
|
|
27
|
+
: undefined;
|
|
28
|
+
if (statuses !== undefined) {
|
|
29
|
+
const known = new Set(["PENDING", "APPROVED", "REJECTED", "ALL"]);
|
|
30
|
+
const invalid = statuses.filter((status) => !known.has(status));
|
|
31
|
+
if (invalid.length > 0)
|
|
32
|
+
throw new UsageError(`Unknown time-off status: ${invalid.join(", ")}; provide PENDING, APPROVED, REJECTED, or ALL`);
|
|
33
|
+
}
|
|
21
34
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
22
35
|
const req = {
|
|
23
36
|
workspaceId,
|
|
24
37
|
page: opts.page,
|
|
25
38
|
pageSize: clampPageSize(opts.limit, 200),
|
|
26
39
|
};
|
|
27
|
-
if (
|
|
28
|
-
req.start =
|
|
29
|
-
if (
|
|
30
|
-
req.end =
|
|
31
|
-
if (
|
|
32
|
-
const statuses = splitList(opts.status).map((s) => s.toUpperCase());
|
|
33
|
-
const known = new Set(["PENDING", "APPROVED", "REJECTED", "ALL"]);
|
|
34
|
-
const invalid = statuses.filter((status) => !known.has(status));
|
|
35
|
-
if (invalid.length > 0)
|
|
36
|
-
throw new Error(`Unknown time-off status: ${invalid.join(", ")}; provide PENDING, APPROVED, REJECTED, or ALL`);
|
|
40
|
+
if (start !== undefined)
|
|
41
|
+
req.start = start;
|
|
42
|
+
if (end !== undefined)
|
|
43
|
+
req.end = end;
|
|
44
|
+
if (statuses !== undefined)
|
|
37
45
|
req.statuses = statuses;
|
|
38
|
-
}
|
|
39
46
|
if (opts.user)
|
|
40
47
|
req.users = splitList(opts.user);
|
|
41
48
|
const response = await client.timeOff.list(req);
|
|
@@ -62,7 +69,7 @@ export const registerTimeOffCommand = (program, services) => {
|
|
|
62
69
|
leafCommand(timeoff, "submit", "write")
|
|
63
70
|
.description("Submit a time-off request against a policy.")
|
|
64
71
|
.addHelpText("after", "\nExamples:\n" +
|
|
65
|
-
" $ clk115 timeoff submit --policy policy_456 --start 2026-07-01\n")
|
|
72
|
+
" $ clk115 timeoff submit --policy policy_456 --start 2026-07-01 --days 1\n")
|
|
66
73
|
.requiredOption("--policy <id>", "Time-off policy ID.")
|
|
67
74
|
.requiredOption("--start <date>", "Period start (date-only YYYY-MM-DD for DAYS-unit policies, RFC3339 for HOURS-unit).")
|
|
68
75
|
.option("--end <date>", "Period end (RFC3339); HOURS-unit policies need it, DAYS-unit use --days. Provide --end or --days.")
|
|
@@ -72,14 +79,14 @@ export const registerTimeOffCommand = (program, services) => {
|
|
|
72
79
|
.option("--half-day-period <period>", "Half-day period (FIRST_HALF, SECOND_HALF, NOT_DEFINED).")
|
|
73
80
|
.action(async function (opts) {
|
|
74
81
|
if (opts.end === undefined && !Number.isFinite(opts.days)) {
|
|
75
|
-
throw new
|
|
82
|
+
throw new UsageError("provide --end (date-range / HOURS-unit policies) or --days (DAYS-unit policies)");
|
|
76
83
|
}
|
|
77
84
|
if (opts.end !== undefined && Number.isFinite(opts.days)) {
|
|
78
|
-
throw new
|
|
85
|
+
throw new UsageError("--end and --days are mutually exclusive: --end for HOURS-unit policies, --days for DAYS-unit policies");
|
|
79
86
|
}
|
|
80
87
|
const halfDayPeriod = opts.halfDayPeriod === undefined ? "NOT_DEFINED" : String(opts.halfDayPeriod).toUpperCase();
|
|
81
88
|
if (!["FIRST_HALF", "SECOND_HALF", "NOT_DEFINED"].includes(halfDayPeriod)) {
|
|
82
|
-
throw new
|
|
89
|
+
throw new UsageError(`--half-day-period must be FIRST_HALF, SECOND_HALF, or NOT_DEFINED (got "${String(opts.halfDayPeriod)}").`);
|
|
83
90
|
}
|
|
84
91
|
const start = requireDateOrRfc3339(opts.start, "start");
|
|
85
92
|
const end = opts.end === undefined
|
|
@@ -104,7 +111,7 @@ export const registerTimeOffCommand = (program, services) => {
|
|
|
104
111
|
policyId: opts.policy,
|
|
105
112
|
body,
|
|
106
113
|
};
|
|
107
|
-
const created = (await client.timeOff.submit(req));
|
|
114
|
+
const created = (await dispatchedWrite(this, client.timeOff.submit(req)));
|
|
108
115
|
const data = {
|
|
109
116
|
id: created.id ?? "",
|
|
110
117
|
user: created.userId ?? "",
|
package/dist/commands/users.js
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
|
+
import { DAYS_OF_WEEK } from "clockify-sdk-ts-115/requests";
|
|
2
|
+
import { UsageError } from "../failure.js";
|
|
1
3
|
import { printObject, printRecords } from "../output.js";
|
|
2
4
|
import { printReceipt } from "../receipt.js";
|
|
5
|
+
import { dispatchedWrite } from "../write-outcome.js";
|
|
3
6
|
import { clampPageSize, parseIntArg, resolveBaseContext, resolveContext } from "./helpers.js";
|
|
4
7
|
import { leafCommand } from "./leaf-command.js";
|
|
5
|
-
const USER_DAYS = [
|
|
6
|
-
"MONDAY",
|
|
7
|
-
"TUESDAY",
|
|
8
|
-
"WEDNESDAY",
|
|
9
|
-
"THURSDAY",
|
|
10
|
-
"FRIDAY",
|
|
11
|
-
"SATURDAY",
|
|
12
|
-
"SUNDAY",
|
|
13
|
-
];
|
|
14
|
-
const userDaysExhaustive = true;
|
|
15
|
-
void userDaysExhaustive;
|
|
16
8
|
function requireUserDay(value, message) {
|
|
17
9
|
const day = String(value).toUpperCase();
|
|
18
|
-
if (!
|
|
19
|
-
throw new
|
|
10
|
+
if (!DAYS_OF_WEEK.includes(day)) {
|
|
11
|
+
throw new UsageError(message);
|
|
20
12
|
}
|
|
21
13
|
return day;
|
|
22
14
|
}
|
|
@@ -66,11 +58,11 @@ export const registerUsersCommand = (program, services) => {
|
|
|
66
58
|
.action(async function (email, opts) {
|
|
67
59
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
68
60
|
const sendEmail = opts.sendEmail !== false;
|
|
69
|
-
await client.workspaces.addUser({
|
|
61
|
+
await dispatchedWrite(this, client.workspaces.addUser({
|
|
70
62
|
workspaceId,
|
|
71
63
|
"send-email": sendEmail ? "true" : "false",
|
|
72
64
|
email,
|
|
73
|
-
});
|
|
65
|
+
}));
|
|
74
66
|
printReceipt({
|
|
75
67
|
ok: true,
|
|
76
68
|
action: "users.invite",
|
|
@@ -110,7 +102,7 @@ export const registerUsersCommand = (program, services) => {
|
|
|
110
102
|
opts.workCapacity !== undefined ||
|
|
111
103
|
(Array.isArray(opts.workingDays) && opts.workingDays.length > 0);
|
|
112
104
|
if (!hasChanges) {
|
|
113
|
-
throw new
|
|
105
|
+
throw new UsageError("users.update-profile needs a change: provide at least one profile field.");
|
|
114
106
|
}
|
|
115
107
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
116
108
|
const body = {};
|
|
@@ -121,18 +113,18 @@ export const registerUsersCommand = (program, services) => {
|
|
|
121
113
|
if (opts.removeImage)
|
|
122
114
|
body.removeProfileImage = true;
|
|
123
115
|
if (opts.weekStart !== undefined) {
|
|
124
|
-
body.weekStart = requireUserDay(opts.weekStart, `--week-start must be one of: ${
|
|
116
|
+
body.weekStart = requireUserDay(opts.weekStart, `--week-start must be one of: ${DAYS_OF_WEEK.join(", ")}.`);
|
|
125
117
|
}
|
|
126
118
|
if (opts.workCapacity !== undefined)
|
|
127
119
|
body.workCapacity = opts.workCapacity;
|
|
128
120
|
if (Array.isArray(opts.workingDays) && opts.workingDays.length > 0) {
|
|
129
121
|
const days = [];
|
|
130
122
|
for (const raw of opts.workingDays) {
|
|
131
|
-
days.push(requireUserDay(raw, `--working-days entries must be one of: ${
|
|
123
|
+
days.push(requireUserDay(raw, `--working-days entries must be one of: ${DAYS_OF_WEEK.join(", ")}.`));
|
|
132
124
|
}
|
|
133
125
|
body.workingDays = days;
|
|
134
126
|
}
|
|
135
|
-
const updated = (await client.memberProfiles.update({ workspaceId, userId, body }));
|
|
127
|
+
const updated = (await dispatchedWrite(this, client.memberProfiles.update({ workspaceId, userId, body })));
|
|
136
128
|
printReceipt({
|
|
137
129
|
ok: true,
|
|
138
130
|
action: "users.update-profile",
|