@apet97/clockify-cli-115 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -5
- package/dist/commands/api.js +2 -2
- package/dist/commands/auditlog.js +10 -4
- package/dist/commands/clients.js +82 -22
- package/dist/commands/doctor.js +7 -11
- package/dist/commands/entries.js +3 -4
- package/dist/commands/expenses.js +22 -17
- package/dist/commands/invoices.js +3 -4
- package/dist/commands/leaf-command.js +45 -0
- package/dist/commands/log.js +5 -4
- package/dist/commands/projects.js +7 -11
- package/dist/commands/reports.js +45 -13
- package/dist/commands/scheduling.js +3 -4
- package/dist/commands/sharedReports.js +214 -39
- package/dist/commands/start.js +2 -2
- package/dist/commands/status.js +27 -3
- package/dist/commands/stop.js +2 -2
- package/dist/commands/tags.js +7 -6
- package/dist/commands/tasks.js +156 -32
- package/dist/commands/timeoff.js +12 -8
- package/dist/commands/users.js +5 -8
- package/dist/commands/webhooks.js +131 -24
- package/dist/config.js +5 -4
- package/dist/error-codes.js +2 -1
- package/dist/generated/version.js +1 -0
- package/dist/index.js +11 -13
- package/dist/output.js +2 -2
- package/package.json +12 -11
package/README.md
CHANGED
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
Command-line interface for [Clockify](https://clockify.me/), built on
|
|
4
4
|
top of `clockify-sdk-ts-115`.
|
|
5
5
|
|
|
6
|
+
Current release: `0.3.0`. Requires Node.js `>=22.13.0` and
|
|
7
|
+
`clockify-sdk-ts-115 >=0.12.0 <1`.
|
|
8
|
+
|
|
6
9
|
Two binaries, identical behavior:
|
|
7
10
|
|
|
8
11
|
- `clockify115` — full name
|
|
@@ -26,7 +29,7 @@ clk115 stop
|
|
|
26
29
|
|
|
27
30
|
In precedence order (highest wins):
|
|
28
31
|
|
|
29
|
-
1. **Command-line flags:** `--
|
|
32
|
+
1. **Command-line flags:** `--workspace`, `--base-url` (credentials are never accepted on argv)
|
|
30
33
|
2. **Environment variables:** `CLOCKIFY_API_KEY`, `CLOCKIFY_WORKSPACE_ID`,
|
|
31
34
|
optional `CLOCKIFY_BASE_URL` for mock/replay or private gateway tests
|
|
32
35
|
3. **Rc file:** `~/.clockifyrc.json` (or `clockifyrc.json` in
|
|
@@ -36,12 +39,14 @@ Rc file shape:
|
|
|
36
39
|
|
|
37
40
|
```json
|
|
38
41
|
{
|
|
39
|
-
"apiKey": "abcd1234…",
|
|
40
42
|
"workspaceId": "65b382b6…",
|
|
41
43
|
"baseUrl": "https://api.clockify.me/api/v1"
|
|
42
44
|
}
|
|
43
45
|
```
|
|
44
46
|
|
|
47
|
+
Legacy rc files containing `apiKey` are rejected with migration guidance. Remove the secret and
|
|
48
|
+
set `CLOCKIFY_API_KEY` in the process environment instead.
|
|
49
|
+
|
|
45
50
|
Do not set `baseUrl` for normal Clockify use. It exists so tests can
|
|
46
51
|
point the CLI at `make mock-clockify` or a replay gateway without
|
|
47
52
|
touching production credentials.
|
|
@@ -207,9 +212,8 @@ npm run build # tsc → dist/
|
|
|
207
212
|
node dist/index.js status # smoke test (or invoke installed clk115/clockify115)
|
|
208
213
|
```
|
|
209
214
|
|
|
210
|
-
`clockify-sdk-ts-115` is
|
|
211
|
-
|
|
212
|
-
future published package.
|
|
215
|
+
`clockify-sdk-ts-115` is workspace-linked for local development and is a
|
|
216
|
+
`>=0.12.0 <1` peer dependency for published consumers.
|
|
213
217
|
|
|
214
218
|
## License
|
|
215
219
|
|
package/dist/commands/api.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import { printJson, printNdjson } from "../output.js";
|
|
3
3
|
import { resolveBaseContext } from "./helpers.js";
|
|
4
|
+
import { leafCommand } from "./leaf-command.js";
|
|
4
5
|
const METHODS = new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
5
6
|
export const registerApiCommand = (program, services) => {
|
|
6
|
-
program
|
|
7
|
-
.command("api")
|
|
7
|
+
leafCommand(program, "api", "destructive")
|
|
8
8
|
.description("Call a Clockify API path directly through the SDK client.")
|
|
9
9
|
.argument("<method>", "HTTP method: GET, POST, PUT, PATCH, or DELETE.")
|
|
10
10
|
.argument("<path>", "API path, e.g. /workspaces/{workspaceId}/tags.")
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { AUDIT_LOG_ACTIONS, } from "clockify-sdk-ts-115/requests";
|
|
1
2
|
import { printRecords } from "../output.js";
|
|
2
3
|
import { clampPageSize, parseIntArg, resolveContext, splitList } from "./helpers.js";
|
|
4
|
+
import { leafCommand } from "./leaf-command.js";
|
|
3
5
|
export const registerAuditLogCommand = (program, services) => {
|
|
4
6
|
const audit = program.command("audit-log").description("Workspace audit log.");
|
|
5
|
-
audit
|
|
6
|
-
.command("search")
|
|
7
|
+
leafCommand(audit, "search", "read")
|
|
7
8
|
.description("Search the workspace audit log.")
|
|
8
9
|
.requiredOption("--start <date>", "Window start (RFC3339, e.g. 2026-05-01T00:00:00Z).")
|
|
9
10
|
.requiredOption("--end <date>", "Window end (RFC3339).")
|
|
@@ -18,6 +19,11 @@ export const registerAuditLogCommand = (program, services) => {
|
|
|
18
19
|
if (actions.length === 0) {
|
|
19
20
|
throw new Error("--actions must include at least one action name");
|
|
20
21
|
}
|
|
22
|
+
const knownActions = new Set(AUDIT_LOG_ACTIONS);
|
|
23
|
+
const invalidActions = actions.filter((action) => !knownActions.has(action));
|
|
24
|
+
if (invalidActions.length > 0) {
|
|
25
|
+
throw new Error(`Unknown audit action(s): ${invalidActions.join(", ")}`);
|
|
26
|
+
}
|
|
21
27
|
const authorIds = opts.authors ? splitList(opts.authors) : [];
|
|
22
28
|
const authors = {
|
|
23
29
|
authorIds,
|
|
@@ -27,10 +33,10 @@ export const registerAuditLogCommand = (program, services) => {
|
|
|
27
33
|
workspaceId,
|
|
28
34
|
start: opts.start,
|
|
29
35
|
end: opts.end,
|
|
30
|
-
actions,
|
|
36
|
+
actions: actions,
|
|
31
37
|
authors,
|
|
32
38
|
page: opts.page,
|
|
33
|
-
"page-size": clampPageSize(opts.limit,
|
|
39
|
+
"page-size": clampPageSize(opts.limit, 50),
|
|
34
40
|
};
|
|
35
41
|
const response = (await client.auditLogReport.search(req));
|
|
36
42
|
const items = Array.isArray(response) ? response : (response.entries ?? []);
|
package/dist/commands/clients.js
CHANGED
|
@@ -1,17 +1,62 @@
|
|
|
1
1
|
import { archiveThenDeleteClient } from "clockify-sdk-ts-115/ensure";
|
|
2
|
-
import { wireBody } from "clockify-sdk-ts-115/requests";
|
|
3
2
|
import { printObject, printRecords } from "../output.js";
|
|
4
3
|
import { printReceipt } from "../receipt.js";
|
|
5
4
|
import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
|
|
5
|
+
import { leafCommand } from "./leaf-command.js";
|
|
6
|
+
function requireClientName(value, source) {
|
|
7
|
+
if (typeof value !== "string" || value.trim() === "") {
|
|
8
|
+
throw new Error(`${source} is missing the required client name; refusing to mutate.`);
|
|
9
|
+
}
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function optionalClientString(value, field) {
|
|
13
|
+
if (value === undefined)
|
|
14
|
+
return undefined;
|
|
15
|
+
if (typeof value !== "string") {
|
|
16
|
+
throw new Error(`Current client has invalid ${field}; refusing to mutate.`);
|
|
17
|
+
}
|
|
18
|
+
return value;
|
|
19
|
+
}
|
|
20
|
+
function optionalNullableClientString(value, field) {
|
|
21
|
+
if (value === null)
|
|
22
|
+
return undefined;
|
|
23
|
+
return optionalClientString(value, field);
|
|
24
|
+
}
|
|
25
|
+
function requiredClientArchived(value) {
|
|
26
|
+
if (typeof value !== "boolean") {
|
|
27
|
+
throw new Error("Current client has invalid or missing archived state; refusing to mutate.");
|
|
28
|
+
}
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
function reconstructClientBody(current, suppliedName) {
|
|
32
|
+
const body = {
|
|
33
|
+
name: suppliedName !== undefined
|
|
34
|
+
? requireClientName(suppliedName, "Client update request")
|
|
35
|
+
: requireClientName(current.name, "Current client"),
|
|
36
|
+
};
|
|
37
|
+
const address = optionalNullableClientString(current.address, "address");
|
|
38
|
+
if (address !== undefined)
|
|
39
|
+
body.address = address;
|
|
40
|
+
const currencyCode = optionalClientString(current.currencyCode, "currencyCode");
|
|
41
|
+
if (currencyCode !== undefined)
|
|
42
|
+
body.currencyCode = currencyCode;
|
|
43
|
+
const email = optionalNullableClientString(current.email, "email");
|
|
44
|
+
if (email !== undefined)
|
|
45
|
+
body.email = email;
|
|
46
|
+
const note = optionalNullableClientString(current.note, "note");
|
|
47
|
+
if (note !== undefined)
|
|
48
|
+
body.note = note;
|
|
49
|
+
body.archived = requiredClientArchived(current.archived);
|
|
50
|
+
return body;
|
|
51
|
+
}
|
|
6
52
|
export const registerClientsCommand = (program, services) => {
|
|
7
53
|
const clients = program.command("clients").description("Manage clients.");
|
|
8
|
-
clients
|
|
9
|
-
.command("list")
|
|
54
|
+
leafCommand(clients, "list", "read")
|
|
10
55
|
.description("List clients in the workspace.")
|
|
11
56
|
.option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
|
|
12
57
|
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
13
58
|
.option("--name <text>", "Filter by client name substring.")
|
|
14
|
-
.option("--archived", "
|
|
59
|
+
.option("--archived", "Show only archived clients (default lists both archived and active).", false)
|
|
15
60
|
.action(async function (opts) {
|
|
16
61
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
17
62
|
const req = {
|
|
@@ -35,8 +80,7 @@ export const registerClientsCommand = (program, services) => {
|
|
|
35
80
|
});
|
|
36
81
|
printRecords(rows, output);
|
|
37
82
|
});
|
|
38
|
-
clients
|
|
39
|
-
.command("create")
|
|
83
|
+
leafCommand(clients, "create", "write")
|
|
40
84
|
.argument("<name>", "Client name.")
|
|
41
85
|
.option("--note <text>", "Client note.")
|
|
42
86
|
.description("Create a client in the workspace.")
|
|
@@ -63,8 +107,7 @@ export const registerClientsCommand = (program, services) => {
|
|
|
63
107
|
],
|
|
64
108
|
}, output);
|
|
65
109
|
});
|
|
66
|
-
clients
|
|
67
|
-
.command("get")
|
|
110
|
+
leafCommand(clients, "get", "read")
|
|
68
111
|
.argument("<id>", "Client ID.")
|
|
69
112
|
.description("Get one client by ID.")
|
|
70
113
|
.action(async function (id) {
|
|
@@ -72,10 +115,9 @@ export const registerClientsCommand = (program, services) => {
|
|
|
72
115
|
const result = await client.clients.get({ workspaceId, clientId: id });
|
|
73
116
|
printObject(result, output);
|
|
74
117
|
});
|
|
75
|
-
clients
|
|
76
|
-
.command("update")
|
|
118
|
+
leafCommand(clients, "update", "write")
|
|
77
119
|
.argument("<id>", "Client ID.")
|
|
78
|
-
.option("--name <text>", "
|
|
120
|
+
.option("--name <text>", "Client name.")
|
|
79
121
|
.option("--note <text>", "Client note.")
|
|
80
122
|
.option("--address <text>", "Client address.")
|
|
81
123
|
.option("--archived", "Archive the client.")
|
|
@@ -83,22 +125,41 @@ export const registerClientsCommand = (program, services) => {
|
|
|
83
125
|
.description("Update a client by ID.")
|
|
84
126
|
.action(async function (id, opts) {
|
|
85
127
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
128
|
+
const hasChanges = opts.name !== undefined ||
|
|
129
|
+
opts.note !== undefined ||
|
|
130
|
+
opts.address !== undefined ||
|
|
131
|
+
opts.archived !== undefined;
|
|
132
|
+
if (!hasChanges) {
|
|
133
|
+
throw new Error("clients.update requires at least one client field to change.");
|
|
134
|
+
}
|
|
135
|
+
const current = (await client.clients.get({
|
|
136
|
+
workspaceId,
|
|
137
|
+
clientId: id,
|
|
138
|
+
}));
|
|
139
|
+
const body = reconstructClientBody(current, opts.name);
|
|
140
|
+
let changed = opts.name !== undefined && opts.name !== current.name;
|
|
141
|
+
if (opts.note !== undefined) {
|
|
142
|
+
changed = changed || opts.note !== body.note;
|
|
90
143
|
body.note = opts.note;
|
|
91
|
-
|
|
144
|
+
}
|
|
145
|
+
if (opts.address !== undefined) {
|
|
146
|
+
changed = changed || opts.address !== body.address;
|
|
92
147
|
body.address = opts.address;
|
|
93
|
-
|
|
148
|
+
}
|
|
149
|
+
if (opts.archived !== undefined) {
|
|
150
|
+
changed = changed || opts.archived !== body.archived;
|
|
94
151
|
body.archived = opts.archived;
|
|
95
|
-
|
|
152
|
+
}
|
|
153
|
+
if (!changed) {
|
|
154
|
+
throw new Error("clients.update values are unchanged; refusing to mutate.");
|
|
155
|
+
}
|
|
156
|
+
const req = {
|
|
96
157
|
workspaceId,
|
|
97
158
|
clientId: id,
|
|
98
159
|
body,
|
|
99
|
-
}
|
|
160
|
+
};
|
|
100
161
|
const updated = (await client.clients.update(req));
|
|
101
|
-
const data = { id: updated.id ?? id, name: updated.name ??
|
|
162
|
+
const data = { id: updated.id ?? id, name: updated.name ?? body.name };
|
|
102
163
|
printReceipt({
|
|
103
164
|
ok: true,
|
|
104
165
|
action: "clients.update",
|
|
@@ -114,8 +175,7 @@ export const registerClientsCommand = (program, services) => {
|
|
|
114
175
|
],
|
|
115
176
|
}, output);
|
|
116
177
|
});
|
|
117
|
-
clients
|
|
118
|
-
.command("delete")
|
|
178
|
+
leafCommand(clients, "delete", "destructive")
|
|
119
179
|
.argument("<id>", "Client ID.")
|
|
120
180
|
.description("Delete a client by ID (archives first; an active client cannot be deleted).")
|
|
121
181
|
.action(async function (id) {
|
package/dist/commands/doctor.js
CHANGED
|
@@ -2,10 +2,10 @@ import { classifyClockifyBaseUrl } from "clockify-sdk-ts-115/create-client";
|
|
|
2
2
|
import { globalFlags, resolveFlags } from "../index.js";
|
|
3
3
|
import { printObject } from "../output.js";
|
|
4
4
|
import { rootProgram } from "./helpers.js";
|
|
5
|
+
import { leafCommand } from "./leaf-command.js";
|
|
5
6
|
const DEFAULT_CLOCKIFY_BASE_URL = "https://api.clockify.me/api/v1";
|
|
6
7
|
export const registerDoctorCommand = (program, services) => {
|
|
7
|
-
program
|
|
8
|
-
.command("doctor")
|
|
8
|
+
leafCommand(program, "doctor", "read")
|
|
9
9
|
.description("Check local CLI configuration without contacting Clockify.")
|
|
10
10
|
.action(function () {
|
|
11
11
|
const root = rootProgram(this);
|
|
@@ -17,7 +17,7 @@ export const registerDoctorCommand = (program, services) => {
|
|
|
17
17
|
};
|
|
18
18
|
function buildDoctorReceipt(config, flags, env) {
|
|
19
19
|
const nodeMajor = Number.parseInt(process.versions.node.split(".")[0] ?? "0", 10);
|
|
20
|
-
const nodeOk = nodeMajor >=
|
|
20
|
+
const nodeOk = nodeMajor >= 22;
|
|
21
21
|
const apiKeySource = sourceFor("apiKey", config, flags, env);
|
|
22
22
|
const workspaceSource = sourceFor("workspaceId", config, flags, env);
|
|
23
23
|
const baseUrlSource = sourceFor("baseUrl", config, flags, env) ?? "default";
|
|
@@ -39,7 +39,7 @@ function buildDoctorReceipt(config, flags, env) {
|
|
|
39
39
|
ok: nodeOk,
|
|
40
40
|
status: nodeOk ? "supported" : "unsupported",
|
|
41
41
|
value: process.versions.node,
|
|
42
|
-
...(nodeOk ? {} : { recovery: "Install Node.js
|
|
42
|
+
...(nodeOk ? {} : { recovery: "Install Node.js 22.13 or newer before using @apet97/clockify-cli-115." }),
|
|
43
43
|
},
|
|
44
44
|
apiKey: {
|
|
45
45
|
ok: apiKeyOk,
|
|
@@ -48,7 +48,7 @@ function buildDoctorReceipt(config, flags, env) {
|
|
|
48
48
|
...(apiKeyOk ? { value: "configured (redacted)" } : {}),
|
|
49
49
|
...(apiKeyOk
|
|
50
50
|
? {}
|
|
51
|
-
: { recovery: "
|
|
51
|
+
: { recovery: "Set CLOCKIFY_API_KEY in the process environment." }),
|
|
52
52
|
},
|
|
53
53
|
workspaceId: {
|
|
54
54
|
ok: workspaceOk,
|
|
@@ -81,9 +81,9 @@ function buildDoctorReceipt(config, flags, env) {
|
|
|
81
81
|
function nextSteps(input) {
|
|
82
82
|
const steps = [];
|
|
83
83
|
if (!input.nodeOk)
|
|
84
|
-
steps.push("Install Node.js
|
|
84
|
+
steps.push("Install Node.js 22.13 or newer.");
|
|
85
85
|
if (!input.apiKeyOk)
|
|
86
|
-
steps.push("Set CLOCKIFY_API_KEY
|
|
86
|
+
steps.push("Set CLOCKIFY_API_KEY in the process environment.");
|
|
87
87
|
if (!input.workspaceOk)
|
|
88
88
|
steps.push("Set CLOCKIFY_WORKSPACE_ID or pass --workspace.");
|
|
89
89
|
if (input.hasBaseUrlOverride) {
|
|
@@ -97,12 +97,8 @@ function nextSteps(input) {
|
|
|
97
97
|
}
|
|
98
98
|
function sourceFor(field, config, flags, env) {
|
|
99
99
|
if (field === "apiKey") {
|
|
100
|
-
if (isPresent(flags.apiKey))
|
|
101
|
-
return "flag";
|
|
102
100
|
if (isPresent(env.CLOCKIFY_API_KEY))
|
|
103
101
|
return "env";
|
|
104
|
-
if (isPresent(config.apiKey))
|
|
105
|
-
return "rc";
|
|
106
102
|
return undefined;
|
|
107
103
|
}
|
|
108
104
|
if (field === "workspaceId") {
|
package/dist/commands/entries.js
CHANGED
|
@@ -2,10 +2,10 @@ import { entityId } from "clockify-sdk-ts-115/operation-receipt";
|
|
|
2
2
|
import { printRecords } from "../output.js";
|
|
3
3
|
import { printReceipt } from "../receipt.js";
|
|
4
4
|
import { clampPageSize, parseIntArg, promoteDateBoundary, resolveContext } from "./helpers.js";
|
|
5
|
+
import { leafCommand } from "./leaf-command.js";
|
|
5
6
|
export const registerEntriesCommand = (program, services) => {
|
|
6
7
|
const entries = program.command("entries").description("Manage time entries.");
|
|
7
|
-
entries
|
|
8
|
-
.command("list")
|
|
8
|
+
leafCommand(entries, "list", "read")
|
|
9
9
|
.description("List the current user's time entries.")
|
|
10
10
|
.option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
|
|
11
11
|
.option("--page <n>", "Page number (default 1).", parseIntArg, 1)
|
|
@@ -47,8 +47,7 @@ export const registerEntriesCommand = (program, services) => {
|
|
|
47
47
|
});
|
|
48
48
|
printRecords(rows, output);
|
|
49
49
|
});
|
|
50
|
-
entries
|
|
51
|
-
.command("delete")
|
|
50
|
+
leafCommand(entries, "delete", "destructive")
|
|
52
51
|
.argument("<id>", "Time-entry ID.")
|
|
53
52
|
.description("Delete a time entry by ID.")
|
|
54
53
|
.action(async function (id) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { entityId } from "clockify-sdk-ts-115/operation-receipt";
|
|
2
|
-
import { wireBody } from "clockify-sdk-ts-115/requests";
|
|
3
2
|
import { printObject, printRecords } from "../output.js";
|
|
4
3
|
import { printReceipt } from "../receipt.js";
|
|
5
4
|
import { clampPageSize, parseFloatArg, parseIntArg, promoteDateBoundary, resolveContext, } from "./helpers.js";
|
|
5
|
+
import { leafCommand } from "./leaf-command.js";
|
|
6
6
|
const EXPENSE_CHANGE_FIELDS = {
|
|
7
7
|
amount: "AMOUNT",
|
|
8
8
|
date: "DATE",
|
|
@@ -19,8 +19,7 @@ function expenseChangeFields(fields) {
|
|
|
19
19
|
}
|
|
20
20
|
export const registerExpensesCommand = (program, services) => {
|
|
21
21
|
const expenses = program.command("expenses").description("Inspect workspace expenses.");
|
|
22
|
-
expenses
|
|
23
|
-
.command("list")
|
|
22
|
+
leafCommand(expenses, "list", "read")
|
|
24
23
|
.description("List expenses in the workspace.")
|
|
25
24
|
.option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
|
|
26
25
|
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
@@ -33,11 +32,7 @@ export const registerExpensesCommand = (program, services) => {
|
|
|
33
32
|
page: opts.page,
|
|
34
33
|
"page-size": clampPageSize(opts.limit, 200),
|
|
35
34
|
};
|
|
36
|
-
|
|
37
|
-
req.start = opts.start;
|
|
38
|
-
if (opts.end)
|
|
39
|
-
req.end = opts.end;
|
|
40
|
-
const response = (await client.expenses.list(wireBody(req)));
|
|
35
|
+
const response = (await client.expenses.list(req));
|
|
41
36
|
const items = (() => {
|
|
42
37
|
const inner = response.expenses;
|
|
43
38
|
if (Array.isArray(inner))
|
|
@@ -63,10 +58,23 @@ export const registerExpensesCommand = (program, services) => {
|
|
|
63
58
|
billable: e.billable === true,
|
|
64
59
|
};
|
|
65
60
|
});
|
|
66
|
-
|
|
61
|
+
const startDay = opts.start;
|
|
62
|
+
const endDay = opts.end;
|
|
63
|
+
const visible = startDay || endDay
|
|
64
|
+
? rows.filter((r) => {
|
|
65
|
+
const day = (r.date ?? "").slice(0, 10);
|
|
66
|
+
if (!day)
|
|
67
|
+
return false;
|
|
68
|
+
if (startDay && day < startDay)
|
|
69
|
+
return false;
|
|
70
|
+
if (endDay && day > endDay)
|
|
71
|
+
return false;
|
|
72
|
+
return true;
|
|
73
|
+
})
|
|
74
|
+
: rows;
|
|
75
|
+
printRecords(visible, output);
|
|
67
76
|
});
|
|
68
|
-
expenses
|
|
69
|
-
.command("create")
|
|
77
|
+
leafCommand(expenses, "create", "write")
|
|
70
78
|
.requiredOption("--amount <n>", "Amount.", parseFloatArg)
|
|
71
79
|
.requiredOption("--category <id>", "Expense category ID.")
|
|
72
80
|
.requiredOption("--date <date>", "Expense date (YYYY-MM-DD or ISO).")
|
|
@@ -120,8 +128,7 @@ export const registerExpensesCommand = (program, services) => {
|
|
|
120
128
|
],
|
|
121
129
|
}, output);
|
|
122
130
|
});
|
|
123
|
-
expenses
|
|
124
|
-
.command("get")
|
|
131
|
+
leafCommand(expenses, "get", "read")
|
|
125
132
|
.argument("<id>", "Expense ID.")
|
|
126
133
|
.description("Get one expense by ID.")
|
|
127
134
|
.action(async function (id) {
|
|
@@ -129,8 +136,7 @@ export const registerExpensesCommand = (program, services) => {
|
|
|
129
136
|
const expense = await client.expenses.get({ workspaceId, expenseId: id });
|
|
130
137
|
printObject(expense, output);
|
|
131
138
|
});
|
|
132
|
-
expenses
|
|
133
|
-
.command("update")
|
|
139
|
+
leafCommand(expenses, "update", "write")
|
|
134
140
|
.argument("<id>", "Expense ID.")
|
|
135
141
|
.requiredOption("--amount <n>", "Amount.", parseFloatArg)
|
|
136
142
|
.requiredOption("--category <id>", "Expense category ID.")
|
|
@@ -180,8 +186,7 @@ export const registerExpensesCommand = (program, services) => {
|
|
|
180
186
|
],
|
|
181
187
|
}, output);
|
|
182
188
|
});
|
|
183
|
-
expenses
|
|
184
|
-
.command("delete")
|
|
189
|
+
leafCommand(expenses, "delete", "destructive")
|
|
185
190
|
.argument("<id>", "Expense ID.")
|
|
186
191
|
.description("Delete an expense by ID.")
|
|
187
192
|
.action(async function (id) {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { printRecords } from "../output.js";
|
|
2
2
|
import { printReceipt } from "../receipt.js";
|
|
3
3
|
import { resolveContext } from "./helpers.js";
|
|
4
|
+
import { leafCommand } from "./leaf-command.js";
|
|
4
5
|
export const registerInvoicesCommand = (program, services) => {
|
|
5
6
|
const invoices = program.command("invoices").description("Manage invoices.");
|
|
6
|
-
invoices
|
|
7
|
-
.command("list")
|
|
7
|
+
leafCommand(invoices, "list", "read")
|
|
8
8
|
.description("List invoices in the workspace.")
|
|
9
9
|
.action(async function () {
|
|
10
10
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
@@ -25,8 +25,7 @@ export const registerInvoicesCommand = (program, services) => {
|
|
|
25
25
|
});
|
|
26
26
|
printRecords(rows, output);
|
|
27
27
|
});
|
|
28
|
-
invoices
|
|
29
|
-
.command("create")
|
|
28
|
+
leafCommand(invoices, "create", "write")
|
|
30
29
|
.description("Create an invoice draft.")
|
|
31
30
|
.requiredOption("--client <id>", "Client ID.")
|
|
32
31
|
.requiredOption("--number <text>", "Invoice number.")
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const commandRisks = new WeakMap();
|
|
2
|
+
export function leafCommand(parent, syntax, risk) {
|
|
3
|
+
if (commandRisks.has(parent)) {
|
|
4
|
+
throw new Error(`A classified leaf cannot become a grouping node: ${parent.name()}`);
|
|
5
|
+
}
|
|
6
|
+
const name = commandName(syntax);
|
|
7
|
+
if (parent.commands.some((command) => command.name() === name)) {
|
|
8
|
+
throw new Error(`Command ${name} is already classified or registered under ${parent.name()}`);
|
|
9
|
+
}
|
|
10
|
+
const command = parent.command(syntax);
|
|
11
|
+
if (commandRisks.has(command)) {
|
|
12
|
+
throw new Error(`Command ${name} is already classified`);
|
|
13
|
+
}
|
|
14
|
+
commandRisks.set(command, risk);
|
|
15
|
+
return command;
|
|
16
|
+
}
|
|
17
|
+
export function collectClassifiedLeaves(root) {
|
|
18
|
+
const leaves = [];
|
|
19
|
+
const visit = (command, path) => {
|
|
20
|
+
const risk = commandRisks.get(command);
|
|
21
|
+
if (command.commands.length > 0) {
|
|
22
|
+
if (risk !== undefined) {
|
|
23
|
+
throw new Error(`Classified command ${path.join(" ")} is a grouping node`);
|
|
24
|
+
}
|
|
25
|
+
for (const child of command.commands) {
|
|
26
|
+
visit(child, [...path, child.name()]);
|
|
27
|
+
}
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (risk === undefined) {
|
|
31
|
+
throw new Error(`Unclassified CLI leaf: ${path.join(" ")}`);
|
|
32
|
+
}
|
|
33
|
+
leaves.push({ command, path, risk });
|
|
34
|
+
};
|
|
35
|
+
for (const command of root.commands) {
|
|
36
|
+
visit(command, [command.name()]);
|
|
37
|
+
}
|
|
38
|
+
return leaves;
|
|
39
|
+
}
|
|
40
|
+
function commandName(syntax) {
|
|
41
|
+
const [name] = syntax.trim().split(/[\s<[\]]/u);
|
|
42
|
+
if (!name)
|
|
43
|
+
throw new Error("Leaf command syntax must include a command name");
|
|
44
|
+
return name;
|
|
45
|
+
}
|
package/dist/commands/log.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { parseDuration } from "../duration.js";
|
|
2
2
|
import { printReceipt } from "../receipt.js";
|
|
3
3
|
import { resolveContext } from "./helpers.js";
|
|
4
|
+
import { leafCommand } from "./leaf-command.js";
|
|
4
5
|
import { resolveProjectId, resolveTaskId, resolveTagIds } from "./resolve-refs.js";
|
|
5
6
|
export const registerLogCommand = (program, services) => {
|
|
6
|
-
program
|
|
7
|
-
.command("log")
|
|
7
|
+
leafCommand(program, "log", "write")
|
|
8
8
|
.description("Log a finished time entry. Duration accepts 1h30m / 90m / PT1H30M.")
|
|
9
9
|
.argument("<duration>", "Duration like '1h30m', '45m', or ISO 8601 'PT1H30M'.")
|
|
10
10
|
.argument("<description>", "What you worked on.")
|
|
@@ -28,11 +28,12 @@ export const registerLogCommand = (program, services) => {
|
|
|
28
28
|
? await resolveTagIds(client, workspaceId, opts.tag)
|
|
29
29
|
: undefined;
|
|
30
30
|
const seconds = parseDuration(duration);
|
|
31
|
-
const
|
|
32
|
-
const endMs = Date.parse(
|
|
31
|
+
const endInput = opts.end ?? new Date().toISOString();
|
|
32
|
+
const endMs = Date.parse(endInput);
|
|
33
33
|
if (Number.isNaN(endMs)) {
|
|
34
34
|
throw new Error(`--end ${JSON.stringify(opts.end)} is not a valid ISO 8601 timestamp`);
|
|
35
35
|
}
|
|
36
|
+
const endIso = new Date(endMs).toISOString();
|
|
36
37
|
const startIso = new Date(endMs - seconds * 1000).toISOString();
|
|
37
38
|
const body = {
|
|
38
39
|
start: startIso,
|
|
@@ -2,15 +2,15 @@ import { archiveThenDeleteProject } from "clockify-sdk-ts-115/ensure";
|
|
|
2
2
|
import { printObject, printRecords } from "../output.js";
|
|
3
3
|
import { printReceipt } from "../receipt.js";
|
|
4
4
|
import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
|
|
5
|
+
import { leafCommand } from "./leaf-command.js";
|
|
5
6
|
export const registerProjectsCommand = (program, services) => {
|
|
6
7
|
const projects = program.command("projects").description("Manage projects.");
|
|
7
|
-
projects
|
|
8
|
-
.command("list")
|
|
8
|
+
leafCommand(projects, "list", "read")
|
|
9
9
|
.description("List projects in the workspace.")
|
|
10
10
|
.option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
|
|
11
11
|
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
12
12
|
.option("--name <text>", "Filter by project name substring.")
|
|
13
|
-
.option("--archived", "
|
|
13
|
+
.option("--archived", "Show only archived projects (default lists both archived and active).", false)
|
|
14
14
|
.option("--client <id>", "Filter by client ID.")
|
|
15
15
|
.action(async function (opts) {
|
|
16
16
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
@@ -39,8 +39,7 @@ export const registerProjectsCommand = (program, services) => {
|
|
|
39
39
|
});
|
|
40
40
|
printRecords(rows, output);
|
|
41
41
|
});
|
|
42
|
-
projects
|
|
43
|
-
.command("create")
|
|
42
|
+
leafCommand(projects, "create", "write")
|
|
44
43
|
.argument("<name>", "Project name.")
|
|
45
44
|
.option("--client <id>", "Client ID.")
|
|
46
45
|
.option("--color <hex>", "Hex color (e.g. #4caf50).")
|
|
@@ -79,8 +78,7 @@ export const registerProjectsCommand = (program, services) => {
|
|
|
79
78
|
],
|
|
80
79
|
}, output);
|
|
81
80
|
});
|
|
82
|
-
projects
|
|
83
|
-
.command("get")
|
|
81
|
+
leafCommand(projects, "get", "read")
|
|
84
82
|
.argument("<id>", "Project ID.")
|
|
85
83
|
.description("Get one project by ID.")
|
|
86
84
|
.action(async function (id) {
|
|
@@ -88,8 +86,7 @@ export const registerProjectsCommand = (program, services) => {
|
|
|
88
86
|
const project = await client.projects.get({ workspaceId, projectId: id });
|
|
89
87
|
printObject(project, output);
|
|
90
88
|
});
|
|
91
|
-
projects
|
|
92
|
-
.command("update")
|
|
89
|
+
leafCommand(projects, "update", "write")
|
|
93
90
|
.argument("<id>", "Project ID.")
|
|
94
91
|
.option("--name <text>", "New project name.")
|
|
95
92
|
.option("--client <id>", "Client ID.")
|
|
@@ -133,8 +130,7 @@ export const registerProjectsCommand = (program, services) => {
|
|
|
133
130
|
],
|
|
134
131
|
}, output);
|
|
135
132
|
});
|
|
136
|
-
projects
|
|
137
|
-
.command("delete")
|
|
133
|
+
leafCommand(projects, "delete", "destructive")
|
|
138
134
|
.argument("<id>", "Project ID.")
|
|
139
135
|
.description("Delete a project by ID (archives first; an active project cannot be deleted).")
|
|
140
136
|
.action(async function (id) {
|