@apet97/clockify-cli-115 5.0.3 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +96 -26
- package/dist/client.js +18 -15
- package/dist/closed-pipe.js +3 -0
- package/dist/commands/api.js +182 -61
- package/dist/commands/approvals.js +9 -7
- package/dist/commands/auditlog.js +11 -8
- package/dist/commands/balanceAssignment.js +10 -8
- package/dist/commands/clients.js +16 -7
- package/dist/commands/doctor.js +42 -25
- package/dist/commands/entries.js +29 -14
- package/dist/commands/expenses.js +64 -22
- package/dist/commands/helpers.js +28 -7
- package/dist/commands/invoices.js +12 -16
- package/dist/commands/leaf-command.js +8 -0
- package/dist/commands/log.js +4 -2
- package/dist/commands/projects.js +18 -9
- package/dist/commands/reports.js +73 -23
- package/dist/commands/resolve-refs.js +30 -53
- package/dist/commands/scheduling.js +94 -40
- package/dist/commands/shared-report-body.js +205 -0
- package/dist/commands/sharedReports.js +19 -215
- package/dist/commands/start.js +6 -4
- package/dist/commands/status.js +55 -19
- package/dist/commands/stop.js +15 -17
- package/dist/commands/tags.js +6 -4
- package/dist/commands/tasks.js +18 -23
- package/dist/commands/timeoff.js +23 -16
- package/dist/commands/users.js +7 -5
- package/dist/commands/webhooks.js +14 -12
- package/dist/completions.js +290 -55
- package/dist/config.js +10 -6
- package/dist/duration.js +5 -4
- package/dist/error-codes.js +34 -6
- package/dist/failure.js +87 -0
- package/dist/flags.js +74 -0
- package/dist/generated/version.js +1 -1
- package/dist/index.js +41 -105
- package/dist/output.js +62 -28
- package/dist/write-outcome.js +84 -0
- package/package.json +3 -3
package/dist/commands/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,5 +1,7 @@
|
|
|
1
|
+
import { UsageError } from "../failure.js";
|
|
1
2
|
import { printObject, printRecords } from "../output.js";
|
|
2
3
|
import { printReceipt } from "../receipt.js";
|
|
4
|
+
import { dispatchedWrite } from "../write-outcome.js";
|
|
3
5
|
import { clampPageSize, parseIntArg, resolveBaseContext, resolveContext } from "./helpers.js";
|
|
4
6
|
import { leafCommand } from "./leaf-command.js";
|
|
5
7
|
const USER_DAYS = [
|
|
@@ -16,7 +18,7 @@ void userDaysExhaustive;
|
|
|
16
18
|
function requireUserDay(value, message) {
|
|
17
19
|
const day = String(value).toUpperCase();
|
|
18
20
|
if (!USER_DAYS.includes(day)) {
|
|
19
|
-
throw new
|
|
21
|
+
throw new UsageError(message);
|
|
20
22
|
}
|
|
21
23
|
return day;
|
|
22
24
|
}
|
|
@@ -66,11 +68,11 @@ export const registerUsersCommand = (program, services) => {
|
|
|
66
68
|
.action(async function (email, opts) {
|
|
67
69
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
68
70
|
const sendEmail = opts.sendEmail !== false;
|
|
69
|
-
await client.workspaces.addUser({
|
|
71
|
+
await dispatchedWrite(this, client.workspaces.addUser({
|
|
70
72
|
workspaceId,
|
|
71
73
|
"send-email": sendEmail ? "true" : "false",
|
|
72
74
|
email,
|
|
73
|
-
});
|
|
75
|
+
}));
|
|
74
76
|
printReceipt({
|
|
75
77
|
ok: true,
|
|
76
78
|
action: "users.invite",
|
|
@@ -110,7 +112,7 @@ export const registerUsersCommand = (program, services) => {
|
|
|
110
112
|
opts.workCapacity !== undefined ||
|
|
111
113
|
(Array.isArray(opts.workingDays) && opts.workingDays.length > 0);
|
|
112
114
|
if (!hasChanges) {
|
|
113
|
-
throw new
|
|
115
|
+
throw new UsageError("users.update-profile needs a change: provide at least one profile field.");
|
|
114
116
|
}
|
|
115
117
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
116
118
|
const body = {};
|
|
@@ -132,7 +134,7 @@ export const registerUsersCommand = (program, services) => {
|
|
|
132
134
|
}
|
|
133
135
|
body.workingDays = days;
|
|
134
136
|
}
|
|
135
|
-
const updated = (await client.memberProfiles.update({ workspaceId, userId, body }));
|
|
137
|
+
const updated = (await dispatchedWrite(this, client.memberProfiles.update({ workspaceId, userId, body })));
|
|
136
138
|
printReceipt({
|
|
137
139
|
ok: true,
|
|
138
140
|
action: "users.update-profile",
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { requestOptions } from "clockify-sdk-ts-115/request-options";
|
|
2
2
|
import { assertSafeWebhookUrl } from "clockify-sdk-ts-115/webhooks";
|
|
3
|
+
import { UsageError } from "../failure.js";
|
|
3
4
|
import { printRecords } from "../output.js";
|
|
4
5
|
import { printReceipt } from "../receipt.js";
|
|
6
|
+
import { dispatchedWrite } from "../write-outcome.js";
|
|
5
7
|
import { resolveContext, splitList } from "./helpers.js";
|
|
6
8
|
import { leafCommand } from "./leaf-command.js";
|
|
7
9
|
const WEBHOOK_LIST_TYPES = ["USER_CREATED", "SYSTEM", "ADDON"];
|
|
@@ -75,25 +77,25 @@ const webhookEventsExhaustive = true;
|
|
|
75
77
|
void webhookEventsExhaustive;
|
|
76
78
|
function nonEmptyString(value, field) {
|
|
77
79
|
if (typeof value !== "string" || value.trim() === "") {
|
|
78
|
-
throw new
|
|
80
|
+
throw new UsageError(`webhooks.create: ${field} must be a non-empty string.`);
|
|
79
81
|
}
|
|
80
82
|
return value;
|
|
81
83
|
}
|
|
82
84
|
function webhookEvent(value) {
|
|
83
85
|
const event = String(value).toUpperCase();
|
|
84
86
|
if (!WEBHOOK_EVENT_TYPES.includes(event)) {
|
|
85
|
-
throw new
|
|
87
|
+
throw new UsageError(`Unknown webhook event: ${String(value)}. Provide a Clockify webhook event type such as NEW_PROJECT or NEW_TIME_ENTRY.`);
|
|
86
88
|
}
|
|
87
89
|
return event;
|
|
88
90
|
}
|
|
89
91
|
function webhookTriggerSourceType(value) {
|
|
90
92
|
const raw = value ?? "WORKSPACE_ID";
|
|
91
93
|
if (typeof raw !== "string") {
|
|
92
|
-
throw new
|
|
94
|
+
throw new UsageError("Unknown trigger source type. Provide one of: PROJECT_ID, USER_ID, TAG_ID, TASK_ID, WORKSPACE_ID, ASSIGNMENT_ID, EXPENSE_ID.");
|
|
93
95
|
}
|
|
94
96
|
const type = raw.toUpperCase();
|
|
95
97
|
if (!WEBHOOK_TRIGGER_SOURCE_TYPES.includes(type)) {
|
|
96
|
-
throw new
|
|
98
|
+
throw new UsageError(`Unknown trigger source type: ${raw}. Provide one of: PROJECT_ID, USER_ID, TAG_ID, TASK_ID, WORKSPACE_ID, ASSIGNMENT_ID, EXPENSE_ID.`);
|
|
97
99
|
}
|
|
98
100
|
return type;
|
|
99
101
|
}
|
|
@@ -106,15 +108,15 @@ export const registerWebhooksCommand = (program, services) => {
|
|
|
106
108
|
" $ clk115 webhooks list --type ADDON\n")
|
|
107
109
|
.option("--type <type>", "Filter by webhook type (USER_CREATED, SYSTEM, ADDON).")
|
|
108
110
|
.action(async function (opts) {
|
|
109
|
-
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
110
111
|
let type;
|
|
111
112
|
if (opts.type) {
|
|
112
113
|
const candidate = String(opts.type).toUpperCase();
|
|
113
114
|
if (!WEBHOOK_LIST_TYPES.includes(candidate)) {
|
|
114
|
-
throw new
|
|
115
|
+
throw new UsageError(`Unknown webhook type: ${opts.type}. Provide one of: ${WEBHOOK_LIST_TYPES.join(", ")}.`);
|
|
115
116
|
}
|
|
116
117
|
type = candidate;
|
|
117
118
|
}
|
|
119
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
118
120
|
const options = type ? requestOptions({ queryParams: { type } }) : undefined;
|
|
119
121
|
const response = (await client.webhooks.list({ workspaceId }, options));
|
|
120
122
|
const items = Array.isArray(response) ? response : (response.webhooks ?? []);
|
|
@@ -142,27 +144,27 @@ export const registerWebhooksCommand = (program, services) => {
|
|
|
142
144
|
.option("--trigger-source-type <type>", "Trigger source type (e.g. PROJECT_ID, USER_ID).")
|
|
143
145
|
.option("--trigger-source <ids>", "Comma-separated trigger source IDs (required when --trigger-source-type is set).")
|
|
144
146
|
.action(async function (opts) {
|
|
145
|
-
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
146
147
|
const name = nonEmptyString(opts.name, "name");
|
|
147
148
|
const url = nonEmptyString(opts.url, "url");
|
|
148
149
|
try {
|
|
149
150
|
assertSafeWebhookUrl(url);
|
|
150
151
|
}
|
|
151
152
|
catch (err) {
|
|
152
|
-
throw new
|
|
153
|
+
throw new UsageError(`webhooks.create: ${err instanceof Error ? err.message : String(err)}`);
|
|
153
154
|
}
|
|
154
155
|
const event = webhookEvent(opts.event);
|
|
155
156
|
const triggerSourceType = webhookTriggerSourceType(opts.triggerSourceType);
|
|
156
157
|
if (USER_ID_TRIGGER_EVENTS.has(event) && triggerSourceType !== "USER_ID") {
|
|
157
|
-
throw new
|
|
158
|
+
throw new UsageError(`webhooks.create: ${event} requires USER_ID trigger sources.`);
|
|
158
159
|
}
|
|
160
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
159
161
|
const triggerSource = triggerSourceType === "WORKSPACE_ID"
|
|
160
162
|
? [workspaceId]
|
|
161
163
|
: opts.triggerSource
|
|
162
164
|
? splitList(String(opts.triggerSource))
|
|
163
165
|
: [];
|
|
164
166
|
if (triggerSource.length === 0) {
|
|
165
|
-
throw new
|
|
167
|
+
throw new UsageError(`webhooks.create: trigger source is required for ${triggerSourceType}.`);
|
|
166
168
|
}
|
|
167
169
|
const body = {
|
|
168
170
|
name,
|
|
@@ -172,7 +174,7 @@ export const registerWebhooksCommand = (program, services) => {
|
|
|
172
174
|
triggerSource,
|
|
173
175
|
};
|
|
174
176
|
const request = { workspaceId, body };
|
|
175
|
-
const created = (await client.webhooks.create(request));
|
|
177
|
+
const created = (await dispatchedWrite(this, client.webhooks.create(request)));
|
|
176
178
|
const data = {
|
|
177
179
|
id: created.id ?? "",
|
|
178
180
|
name: created.name ?? "",
|
|
@@ -201,7 +203,7 @@ export const registerWebhooksCommand = (program, services) => {
|
|
|
201
203
|
.addHelpText("after", "\nExamples:\n" + " $ clk115 webhooks delete webhook_123\n")
|
|
202
204
|
.action(async function (id) {
|
|
203
205
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
204
|
-
await client.webhooks.delete({ workspaceId, webhookId: id });
|
|
206
|
+
await dispatchedWrite(this, client.webhooks.delete({ workspaceId, webhookId: id }));
|
|
205
207
|
printReceipt({
|
|
206
208
|
ok: true,
|
|
207
209
|
action: "webhooks.delete",
|
package/dist/completions.js
CHANGED
|
@@ -1,67 +1,302 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"users",
|
|
22
|
-
"approvals",
|
|
23
|
-
"completion",
|
|
24
|
-
"help",
|
|
25
|
-
];
|
|
26
|
-
export function renderCompletion(shell) {
|
|
27
|
-
const commands = COMMANDS.join(" ");
|
|
1
|
+
import { InvalidArgumentError } from "commander";
|
|
2
|
+
import { KNOWN_REGIONS } from "./client.js";
|
|
3
|
+
import { TIME_VIEW_MODES } from "./commands/helpers.js";
|
|
4
|
+
export const COMPLETION_SHELLS = ["zsh", "bash", "fish"];
|
|
5
|
+
const BINARIES = ["clk115", "clockify115"];
|
|
6
|
+
const FLAG_VALUES = {
|
|
7
|
+
"--output": ["table", "json", "ndjson"],
|
|
8
|
+
"--region": KNOWN_REGIONS,
|
|
9
|
+
"--time-view-mode": TIME_VIEW_MODES,
|
|
10
|
+
};
|
|
11
|
+
export function parseCompletionShell(value) {
|
|
12
|
+
const shell = (value ?? "zsh").toLowerCase();
|
|
13
|
+
const match = COMPLETION_SHELLS.find((candidate) => candidate === shell);
|
|
14
|
+
if (match === undefined) {
|
|
15
|
+
throw new InvalidArgumentError(`completion shell must be one of: ${COMPLETION_SHELLS.join(", ")}`);
|
|
16
|
+
}
|
|
17
|
+
return match;
|
|
18
|
+
}
|
|
19
|
+
export function renderCompletion(shell, program) {
|
|
20
|
+
const nodes = collectNodes(program);
|
|
28
21
|
if (shell === "zsh")
|
|
29
|
-
return renderZsh(
|
|
22
|
+
return renderZsh(nodes);
|
|
30
23
|
if (shell === "bash")
|
|
31
|
-
return renderBash(
|
|
32
|
-
return renderFish();
|
|
24
|
+
return renderBash(nodes);
|
|
25
|
+
return renderFish(nodes);
|
|
33
26
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
27
|
+
function oneLine(text) {
|
|
28
|
+
return (text.split("\n")[0] ?? "").replace(/\s+/g, " ").trim();
|
|
29
|
+
}
|
|
30
|
+
function toFlag(option) {
|
|
31
|
+
const names = [option.long, option.short].filter((name) => name != null);
|
|
32
|
+
const long = option.long ?? "";
|
|
33
|
+
return {
|
|
34
|
+
names,
|
|
35
|
+
description: oneLine(option.description),
|
|
36
|
+
takesValue: option.required || option.optional,
|
|
37
|
+
values: option.argChoices ?? FLAG_VALUES[long] ?? [],
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
const HELP_FLAG = {
|
|
41
|
+
names: ["--help", "-h"],
|
|
42
|
+
description: "display help for command",
|
|
43
|
+
takesValue: false,
|
|
44
|
+
values: [],
|
|
45
|
+
};
|
|
46
|
+
export function collectNodes(program) {
|
|
47
|
+
const nodes = [];
|
|
48
|
+
const visit = (command, path) => {
|
|
49
|
+
const isRoot = path.length === 0;
|
|
50
|
+
const subcommands = command.commands.map((child) => ({
|
|
51
|
+
name: child.name(),
|
|
52
|
+
description: oneLine(child.description()),
|
|
53
|
+
}));
|
|
54
|
+
if (isRoot)
|
|
55
|
+
subcommands.push({ name: "help", description: "display help for command" });
|
|
56
|
+
const flags = command.options.filter((option) => !option.hidden).map(toFlag);
|
|
57
|
+
if (isRoot) {
|
|
58
|
+
flags.push({
|
|
59
|
+
names: ["--version", "-V"],
|
|
60
|
+
description: "output the version number",
|
|
61
|
+
takesValue: false,
|
|
62
|
+
values: [],
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
flags.push(HELP_FLAG);
|
|
66
|
+
nodes.push({
|
|
67
|
+
path: path.join(" "),
|
|
68
|
+
subcommands,
|
|
69
|
+
flags: dedupeFlags(flags),
|
|
70
|
+
argumentValues: command.registeredArguments[0]?.argChoices ?? [],
|
|
71
|
+
});
|
|
72
|
+
for (const child of command.commands)
|
|
73
|
+
visit(child, [...path, child.name()]);
|
|
74
|
+
};
|
|
75
|
+
visit(program, []);
|
|
76
|
+
return nodes;
|
|
77
|
+
}
|
|
78
|
+
function dedupeFlags(flags) {
|
|
79
|
+
const seen = new Set();
|
|
80
|
+
return flags.filter((flag) => {
|
|
81
|
+
const key = flag.names[0] ?? "";
|
|
82
|
+
if (seen.has(key))
|
|
83
|
+
return false;
|
|
84
|
+
seen.add(key);
|
|
85
|
+
return true;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function flagsFor(node, root) {
|
|
89
|
+
return node === root ? node.flags : dedupeFlags([...node.flags, ...root.flags]);
|
|
90
|
+
}
|
|
91
|
+
function rootOf(nodes) {
|
|
92
|
+
const root = nodes.find((node) => node.path === "");
|
|
93
|
+
if (root === undefined)
|
|
94
|
+
throw new Error("completion tree has no root node");
|
|
95
|
+
return root;
|
|
96
|
+
}
|
|
97
|
+
function valueFlagNames(nodes) {
|
|
98
|
+
const names = new Set();
|
|
99
|
+
for (const node of nodes) {
|
|
100
|
+
for (const flag of node.flags) {
|
|
101
|
+
if (flag.takesValue)
|
|
102
|
+
for (const name of flag.names)
|
|
103
|
+
names.add(name);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return [...names].sort();
|
|
107
|
+
}
|
|
108
|
+
function flagValueTable(nodes) {
|
|
109
|
+
const byName = new Map();
|
|
110
|
+
for (const node of nodes) {
|
|
111
|
+
for (const flag of node.flags) {
|
|
112
|
+
if (flag.values.length === 0)
|
|
113
|
+
continue;
|
|
114
|
+
for (const name of flag.names)
|
|
115
|
+
byName.set(name, flag.values);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return [...byName].map(([name, values]) => ({ names: [name], values: [...values] }));
|
|
119
|
+
}
|
|
120
|
+
function shQuote(text) {
|
|
121
|
+
return `'${text.replaceAll("'", "'\\''")}'`;
|
|
122
|
+
}
|
|
123
|
+
function posixPathWalk(nodes, first, wordAt, limit) {
|
|
124
|
+
const paths = nodes.filter((node) => node.path !== "").map((node) => shQuote(node.path));
|
|
125
|
+
const valueFlags = valueFlagNames(nodes).map(shQuote).join("|");
|
|
126
|
+
return ` local cmdpath="" candidate word skip=0 i
|
|
127
|
+
for (( i = ${first}; i < ${limit}; i++ )); do
|
|
128
|
+
word="${wordAt}"
|
|
129
|
+
if (( skip )); then skip=0; continue; fi
|
|
130
|
+
case "$word" in
|
|
131
|
+
${valueFlags}) skip=1; continue ;;
|
|
132
|
+
-*) continue ;;
|
|
133
|
+
esac
|
|
134
|
+
candidate="\${cmdpath:+$cmdpath }$word"
|
|
135
|
+
case "$candidate" in
|
|
136
|
+
${paths.join("|")}) cmdpath="$candidate" ;;
|
|
137
|
+
esac
|
|
138
|
+
done`;
|
|
139
|
+
}
|
|
140
|
+
function renderBash(nodes) {
|
|
141
|
+
const root = rootOf(nodes);
|
|
142
|
+
const words = (items) => shQuote(items.join(" "));
|
|
143
|
+
const nodeCases = nodes
|
|
144
|
+
.map((node) => {
|
|
145
|
+
const commands = [...node.subcommands.map((sub) => sub.name), ...node.argumentValues];
|
|
146
|
+
const flags = flagsFor(node, root).flatMap((flag) => flag.names);
|
|
147
|
+
return ` ${shQuote(node.path)}) subcmds=${words(commands)}; flags=${words(flags)} ;;`;
|
|
148
|
+
})
|
|
149
|
+
.join("\n");
|
|
150
|
+
const valueCases = flagValueTable(nodes)
|
|
151
|
+
.map(({ names, values }) => ` ${names.map(shQuote).join("|")}) values=${words(values)} ;;`)
|
|
152
|
+
.join("\n");
|
|
153
|
+
const valueFlags = valueFlagNames(nodes).map(shQuote).join("|");
|
|
154
|
+
return `# bash completion for clk115 / clockify115.
|
|
155
|
+
# Generated by @apet97/clockify-cli-115 from its command tree.
|
|
156
|
+
_clk115_completion() {
|
|
157
|
+
local cur="\${COMP_WORDS[COMP_CWORD]}" prev="" subcmds="" flags="" values=""
|
|
158
|
+
if (( COMP_CWORD > 0 )); then prev="\${COMP_WORDS[COMP_CWORD-1]}"; fi
|
|
159
|
+
${posixPathWalk(nodes, 1, "${COMP_WORDS[i]}", "COMP_CWORD")}
|
|
160
|
+
case "$prev" in
|
|
161
|
+
${valueCases}
|
|
162
|
+
${valueFlags}) COMPREPLY=(); return 0 ;;
|
|
163
|
+
esac
|
|
164
|
+
if [[ -n "$values" ]]; then
|
|
165
|
+
COMPREPLY=( $(compgen -W "$values" -- "$cur") )
|
|
166
|
+
return 0
|
|
167
|
+
fi
|
|
168
|
+
case "$cmdpath" in
|
|
169
|
+
${nodeCases}
|
|
170
|
+
esac
|
|
171
|
+
if [[ "$cur" == -* ]]; then
|
|
172
|
+
COMPREPLY=( $(compgen -W "$flags" -- "$cur") )
|
|
173
|
+
else
|
|
174
|
+
COMPREPLY=( $(compgen -W "$subcmds" -- "$cur") )
|
|
175
|
+
fi
|
|
176
|
+
}
|
|
177
|
+
${BINARIES.map((binary) => `complete -o default -F _clk115_completion ${binary}`).join("\n")}
|
|
178
|
+
`;
|
|
39
179
|
}
|
|
40
|
-
function renderZsh(
|
|
41
|
-
|
|
42
|
-
|
|
180
|
+
function renderZsh(nodes) {
|
|
181
|
+
const root = rootOf(nodes);
|
|
182
|
+
const entry = (name, description) => shQuote(`${name.replaceAll(":", "\\:")}:${description}`);
|
|
183
|
+
const nodeCases = nodes
|
|
184
|
+
.map((node) => {
|
|
185
|
+
const commands = [
|
|
186
|
+
...node.subcommands.map((sub) => entry(sub.name, sub.description)),
|
|
187
|
+
...node.argumentValues.map((value) => entry(value, "")),
|
|
188
|
+
];
|
|
189
|
+
const flags = flagsFor(node, root).flatMap((flag) => flag.names.map((name) => entry(name, flag.description)));
|
|
190
|
+
return ` ${shQuote(node.path)})
|
|
191
|
+
subcmds=(${commands.join(" ")})
|
|
192
|
+
flags=(${flags.join(" ")})
|
|
193
|
+
;;`;
|
|
194
|
+
})
|
|
195
|
+
.join("\n");
|
|
196
|
+
const valueCases = flagValueTable(nodes)
|
|
197
|
+
.map(({ names, values }) => ` ${names.map(shQuote).join("|")}) compadd -- ${values.map(shQuote).join(" ")}; return ;;`)
|
|
198
|
+
.join("\n");
|
|
199
|
+
const valueFlags = valueFlagNames(nodes).map(shQuote).join("|");
|
|
200
|
+
return `#compdef ${BINARIES.join(" ")}
|
|
201
|
+
# zsh completion for clk115 / clockify115.
|
|
202
|
+
# Generated by @apet97/clockify-cli-115 from its command tree.
|
|
43
203
|
_clk115() {
|
|
44
|
-
local -a
|
|
45
|
-
|
|
46
|
-
|
|
204
|
+
local -a subcmds flags
|
|
205
|
+
${posixPathWalk(nodes, 2, "${words[i]}", "CURRENT")}
|
|
206
|
+
case "\${words[CURRENT-1]}" in
|
|
207
|
+
${valueCases}
|
|
208
|
+
${valueFlags}) _files; return ;;
|
|
209
|
+
esac
|
|
210
|
+
case "$cmdpath" in
|
|
211
|
+
${nodeCases}
|
|
212
|
+
esac
|
|
213
|
+
if [[ "\${words[CURRENT]}" == -* ]]; then
|
|
214
|
+
_describe -t options 'option' flags
|
|
215
|
+
else
|
|
216
|
+
_describe -t commands 'command' subcmds
|
|
217
|
+
fi
|
|
47
218
|
}
|
|
48
|
-
|
|
49
|
-
|
|
219
|
+
# Works both ways: autoloaded from $fpath (the file body IS the function, so
|
|
220
|
+
# run it), or sourced from ~/.zshrc (register it for both binaries).
|
|
221
|
+
if [[ "\${funcstack[1]}" == "_clk115" ]]; then
|
|
222
|
+
_clk115 "$@"
|
|
223
|
+
else
|
|
224
|
+
${BINARIES.map((binary) => ` compdef _clk115 ${binary}`).join("\n")}
|
|
225
|
+
fi
|
|
50
226
|
`;
|
|
51
227
|
}
|
|
52
|
-
function
|
|
53
|
-
return `
|
|
54
|
-
local cur
|
|
55
|
-
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
56
|
-
COMPREPLY=( $(compgen -W "${commands}" -- "$cur") )
|
|
228
|
+
function fishQuote(text) {
|
|
229
|
+
return `'${text.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
|
|
57
230
|
}
|
|
58
|
-
|
|
59
|
-
|
|
231
|
+
function renderFish(nodes) {
|
|
232
|
+
const root = rootOf(nodes);
|
|
233
|
+
const paths = nodes.filter((node) => node.path !== "").map((node) => fishQuote(node.path));
|
|
234
|
+
const valueFlags = valueFlagNames(nodes).map(fishQuote).join(" ");
|
|
235
|
+
const lines = [];
|
|
236
|
+
for (const binary of BINARIES) {
|
|
237
|
+
lines.push(`complete -c ${binary} -f`);
|
|
238
|
+
for (const node of nodes) {
|
|
239
|
+
const at = `-n ${fishQuote(`__clk115_at ${fishQuote(node.path)}`)}`;
|
|
240
|
+
for (const sub of node.subcommands) {
|
|
241
|
+
lines.push(`complete -c ${binary} ${at} -a ${fishQuote(sub.name)} -d ${fishQuote(sub.description)}`);
|
|
242
|
+
}
|
|
243
|
+
if (node.argumentValues.length > 0) {
|
|
244
|
+
lines.push(`complete -c ${binary} ${at} -a ${fishQuote(node.argumentValues.join(" "))}`);
|
|
245
|
+
}
|
|
246
|
+
for (const flag of node.flags) {
|
|
247
|
+
const condition = node === root ? "" : `${at} `;
|
|
248
|
+
if (node !== root && root.flags.some((global) => global.names[0] === flag.names[0])) {
|
|
249
|
+
continue;
|
|
250
|
+
}
|
|
251
|
+
lines.push(`complete -c ${binary} ${condition}${fishFlag(flag)}`);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return `# fish completion for clk115 / clockify115.
|
|
256
|
+
# Generated by @apet97/clockify-cli-115 from its command tree.
|
|
257
|
+
function __clk115_path
|
|
258
|
+
set -l tokens (commandline -opc)
|
|
259
|
+
set -e tokens[1]
|
|
260
|
+
set -l cmdpath
|
|
261
|
+
set -l skip 0
|
|
262
|
+
for token in $tokens
|
|
263
|
+
if test $skip -eq 1
|
|
264
|
+
set skip 0
|
|
265
|
+
continue
|
|
266
|
+
end
|
|
267
|
+
if contains -- $token ${valueFlags}
|
|
268
|
+
set skip 1
|
|
269
|
+
continue
|
|
270
|
+
end
|
|
271
|
+
if string match -q -- '-*' $token
|
|
272
|
+
continue
|
|
273
|
+
end
|
|
274
|
+
set -l candidate (string join ' ' $cmdpath $token)
|
|
275
|
+
if contains -- "$candidate" ${paths.join(" ")}
|
|
276
|
+
set cmdpath $cmdpath $token
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
string join ' ' $cmdpath
|
|
280
|
+
end
|
|
281
|
+
function __clk115_at
|
|
282
|
+
set -l current (__clk115_path)
|
|
283
|
+
test "$current" = "$argv[1]"
|
|
284
|
+
end
|
|
285
|
+
${lines.join("\n")}
|
|
60
286
|
`;
|
|
61
287
|
}
|
|
62
|
-
function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
288
|
+
function fishFlag(flag) {
|
|
289
|
+
const parts = [];
|
|
290
|
+
for (const name of flag.names) {
|
|
291
|
+
parts.push(name.startsWith("--") ? `-l ${name.slice(2)}` : `-s ${name.slice(1)}`);
|
|
292
|
+
}
|
|
293
|
+
if (flag.values.length > 0) {
|
|
294
|
+
parts.push(`-x -a ${fishQuote(flag.values.join(" "))}`);
|
|
295
|
+
}
|
|
296
|
+
else if (flag.takesValue) {
|
|
297
|
+
parts.push("-r");
|
|
298
|
+
}
|
|
299
|
+
if (flag.description)
|
|
300
|
+
parts.push(`-d ${fishQuote(flag.description)}`);
|
|
301
|
+
return parts.join(" ");
|
|
67
302
|
}
|
package/dist/config.js
CHANGED
|
@@ -2,6 +2,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
const KNOWN_RC_FILE_KEYS = ["workspaceId", "baseUrl", "region", "subdomain"];
|
|
5
|
+
const SECRET_RC_FILE_KEY = /api[-_]?key|token|secret|password|credential/i;
|
|
5
6
|
function editDistance(left, right) {
|
|
6
7
|
let previous = Array.from({ length: right.length + 1 }, (_, index) => index);
|
|
7
8
|
for (let leftIndex = 0; leftIndex < left.length; leftIndex += 1) {
|
|
@@ -58,23 +59,26 @@ export function requireWorkspaceId(config) {
|
|
|
58
59
|
return config.workspaceId;
|
|
59
60
|
}
|
|
60
61
|
function loadRcFile(env) {
|
|
61
|
-
const root = env.CLOCKIFY_HOME ?? homedir();
|
|
62
|
+
const root = firstPresent(env.CLOCKIFY_HOME) ?? homedir();
|
|
62
63
|
const candidates = [join(root, "clockifyrc.json"), join(root, ".clockifyrc.json")];
|
|
63
64
|
for (const path of candidates) {
|
|
64
65
|
if (!existsSync(path)) {
|
|
65
66
|
continue;
|
|
66
67
|
}
|
|
67
|
-
let parsed
|
|
68
|
+
let parsed;
|
|
68
69
|
try {
|
|
69
|
-
|
|
70
|
-
parsed = JSON.parse(raw);
|
|
70
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
71
71
|
}
|
|
72
72
|
catch (err) {
|
|
73
73
|
const reason = err instanceof Error ? err.message : String(err);
|
|
74
74
|
throw new Error(`failed to read Clockify rc file ${path}: ${reason}`);
|
|
75
75
|
}
|
|
76
|
-
if (
|
|
77
|
-
throw new Error(
|
|
76
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
77
|
+
throw new Error(`Clockify rc file ${path} must contain a JSON object such as {"workspaceId":"..."}; fix or remove the file`);
|
|
78
|
+
}
|
|
79
|
+
const secretKeys = Object.keys(parsed).filter((key) => SECRET_RC_FILE_KEY.test(key));
|
|
80
|
+
if (secretKeys.length > 0) {
|
|
81
|
+
throw new Error(`legacy rc-file secret detected: remove ${secretKeys.join(", ")} from the rc file and set CLOCKIFY_API_KEY in the process environment`);
|
|
78
82
|
}
|
|
79
83
|
for (const key of Object.keys(parsed)) {
|
|
80
84
|
if (KNOWN_RC_FILE_KEYS.includes(key))
|