@apet97/clockify-cli-115 6.0.0 → 8.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 +167 -21
- package/dist/client.js +30 -7
- package/dist/commands/api.js +44 -76
- package/dist/commands/approvals.js +2 -5
- package/dist/commands/auth.js +229 -0
- package/dist/commands/balanceAssignment.js +5 -12
- package/dist/commands/batch.js +226 -0
- package/dist/commands/clients.js +18 -79
- package/dist/commands/doctor.js +65 -66
- package/dist/commands/entries.js +5 -8
- package/dist/commands/expenses.js +29 -39
- package/dist/commands/helpers.js +68 -30
- package/dist/commands/invoices.js +3 -3
- package/dist/commands/leaf-command.js +7 -0
- package/dist/commands/manifest.js +63 -0
- package/dist/commands/operations.js +271 -0
- package/dist/commands/projects.js +17 -37
- package/dist/commands/reports.js +22 -7
- package/dist/commands/shared-report-body.js +14 -81
- package/dist/commands/sharedReports.js +8 -47
- package/dist/commands/skill.js +85 -0
- package/dist/commands/status.js +19 -13
- package/dist/commands/stop.js +3 -12
- package/dist/commands/tags.js +12 -21
- package/dist/commands/tasks.js +26 -134
- package/dist/commands/timeoff.js +1 -1
- package/dist/commands/users.js +4 -14
- package/dist/commands/webhook-delivery.js +331 -0
- package/dist/commands/webhooks.js +37 -110
- package/dist/completions.js +2 -1
- package/dist/config.js +166 -63
- package/dist/credentials.js +164 -0
- package/dist/failure.js +4 -9
- package/dist/flags.js +14 -4
- package/dist/generated/version.js +1 -1
- package/dist/index.js +38 -15
- package/dist/interrupts.js +28 -0
- package/dist/output.js +137 -48
- package/dist/receipt.js +2 -10
- package/dist/stdin.js +6 -0
- package/dist/stdout.js +38 -0
- package/dist/write-outcome.js +1 -1
- package/package.json +5 -3
- 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 -300
package/README.md
CHANGED
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Command-line interface for [Clockify](https://clockify.me/), built on
|
|
4
4
|
top of `clockify-sdk-ts-115`.
|
|
5
5
|
|
|
6
|
-
Version in this checkout: `
|
|
7
|
-
`clockify-sdk-ts-115 ^
|
|
6
|
+
Version in this checkout: `8.0.0`. Requires Node.js `>=22.13.0` and
|
|
7
|
+
`clockify-sdk-ts-115 ^7.0.0`.
|
|
8
8
|
|
|
9
9
|
Two binaries, identical behavior:
|
|
10
10
|
|
|
@@ -17,8 +17,7 @@ npm run build -w clockify-sdk-ts-115 # build the workspace-linked SDK
|
|
|
17
17
|
cd cli
|
|
18
18
|
npm run build
|
|
19
19
|
npm link
|
|
20
|
-
|
|
21
|
-
export CLOCKIFY_WORKSPACE_ID=... # from a workspace URL
|
|
20
|
+
clk115 auth login # or: export CLOCKIFY_API_KEY=... and CLOCKIFY_WORKSPACE_ID=...
|
|
22
21
|
|
|
23
22
|
clk115 status
|
|
24
23
|
clk115 projects list --limit 5
|
|
@@ -28,13 +27,43 @@ clk115 stop
|
|
|
28
27
|
|
|
29
28
|
See the [MCP host compatibility guide](../docs/mcp-host-compatibility.md) for client setup and Reports App support.
|
|
30
29
|
|
|
30
|
+
## Credentials
|
|
31
|
+
|
|
32
|
+
`clk115 auth login` reads the API key from stdin or a hidden prompt, checks it with Clockify, and keeps it in the OS
|
|
33
|
+
keychain (macOS keychain, or the Secret Service through `secret-tool` on Linux). Other platforms have no store: set
|
|
34
|
+
`CLOCKIFY_API_KEY` there. A key is never read from an argument and never written to a file.
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
clk115 auth login # the first profile becomes the current one
|
|
38
|
+
clk115 auth login --profile sandbox --workspace 64c777ddd3fcab07cfbb210c
|
|
39
|
+
clk115 auth use sandbox
|
|
40
|
+
clk115 auth status --json # which key is used, checked with Clockify
|
|
41
|
+
clk115 auth exec -- clockify115-mcp # run a program with the credential in its environment
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
- `CLOCKIFY_API_KEY` in the environment wins over the current profile. An explicit `--profile` wins over the whole
|
|
45
|
+
environment: no `CLOCKIFY_*` key, workspace or route applies. `CLOCKIFY_API_KEY` and `CLOCKIFY_PROFILE` together are
|
|
46
|
+
an error.
|
|
47
|
+
- A stored key belongs to one profile and one route: the region and subdomain, or the scheme, host and port of
|
|
48
|
+
`--base-url`. With another route it is not found, so it is never sent there. A route without `--base-url` has up to three hosts, all of them Clockify's: the API,
|
|
49
|
+
the reports, and the audit log, which Clockify serves for every region from one host.
|
|
50
|
+
- `auth login` takes the route from its flags or from the profile it replaces, not from the environment or the top of
|
|
51
|
+
the rc file. A new profile uses the global host unless you pass `--region`, `--subdomain` or `--base-url`.
|
|
52
|
+
- `auth exec` gives the program the route that the key was stored for, whatever its own environment or rc file says.
|
|
53
|
+
Ctrl-C in a terminal reaches the program directly. SIGTERM and SIGHUP are passed on to it; a SIGINT sent to `clk115`
|
|
54
|
+
alone is passed on only without a terminal, because it would reach a program in the same terminal twice.
|
|
55
|
+
- `auth logout` deletes the key from the keychain. It stays valid in Clockify until you replace it there.
|
|
56
|
+
- Any program that runs as you can ask the keychain for the key. The gain over a shell profile is that the key is
|
|
57
|
+
encrypted at rest and appears in no file, argument or host configuration.
|
|
58
|
+
|
|
31
59
|
## Configuration
|
|
32
60
|
|
|
33
61
|
In precedence order (highest wins):
|
|
34
62
|
|
|
35
|
-
1. **Command-line flags:** `--workspace`, `--base-url`, `--region`, `--subdomain`
|
|
63
|
+
1. **Command-line flags:** `--workspace`, `--base-url`, `--region`, `--subdomain`, `--profile`
|
|
36
64
|
(credentials are never accepted on argv)
|
|
37
65
|
2. **Environment variables:** `CLOCKIFY_API_KEY`, `CLOCKIFY_WORKSPACE_ID`,
|
|
66
|
+
`CLOCKIFY_PROFILE`,
|
|
38
67
|
optional `CLOCKIFY_BASE_URL` for mock/replay or private gateway tests,
|
|
39
68
|
optional `CLOCKIFY_REGION`/`CLOCKIFY_SUBDOMAIN` for regional routing
|
|
40
69
|
3. **Rc file:** `clockifyrc.json`, then `.clockifyrc.json`, both looked up in
|
|
@@ -53,10 +82,19 @@ Rc file shape:
|
|
|
53
82
|
{
|
|
54
83
|
"workspaceId": "65b382b6…",
|
|
55
84
|
"region": "eu",
|
|
56
|
-
"subdomain": "acme"
|
|
85
|
+
"subdomain": "acme",
|
|
86
|
+
"profile": "sandbox",
|
|
87
|
+
"profiles": { "sandbox": { "workspaceId": "64c777dd…" } }
|
|
57
88
|
}
|
|
58
89
|
```
|
|
59
90
|
|
|
91
|
+
`auth login`, `auth use` and `auth logout` maintain `profile` and `profiles`. A selected profile uses its own workspace
|
|
92
|
+
and route, not the ones beside it in the file.
|
|
93
|
+
|
|
94
|
+
A route in the rc file or the profile is used as a whole. When a flag or a variable names a base URL or a region,
|
|
95
|
+
`baseUrl`, `region` and `subdomain` of the file do not apply. A subdomain alone (`--subdomain`, `CLOCKIFY_SUBDOMAIN`)
|
|
96
|
+
refines that route. Flags and variables combine: `--region us` with `CLOCKIFY_SUBDOMAIN=acme` is `acme` in the US.
|
|
97
|
+
|
|
60
98
|
For each unknown rc-file key, the CLI writes one warning to stderr, names the
|
|
61
99
|
nearest known key, ignores the unknown key, and continues.
|
|
62
100
|
|
|
@@ -70,15 +108,29 @@ touching production credentials.
|
|
|
70
108
|
## Output modes
|
|
71
109
|
|
|
72
110
|
- **Default:** human-friendly tables via `cli-table3`.
|
|
73
|
-
- **`--output <mode>`:** `table`, `json`, or `
|
|
111
|
+
- **`--output <mode>`:** `table`, `json`, `ndjson`, or `csv`. `--json` is a
|
|
74
112
|
shortcut for `--output json`.
|
|
113
|
+
- **`--fields <a,b.c>`:** print only these fields, in this order; dots reach nested fields. Works in every mode. A field
|
|
114
|
+
that no record has prints as null (empty in a table or CSV), with a warning. Where the fields do not depend on what
|
|
115
|
+
Clockify answers (`batch`, `operations`, `webhooks listen`, `doctor` and others), an unknown one is a usage error
|
|
116
|
+
before anything is sent.
|
|
75
117
|
- **`--compact`:** single-line JSON without indentation.
|
|
76
118
|
- **`--select <path>`:** print a dot-path (e.g. `--select data.id` or
|
|
77
|
-
`--select 0.name`) before emitting JSON or NDJSON.
|
|
119
|
+
`--select 0.name`) before emitting JSON or NDJSON. An unknown path is treated like an unknown field.
|
|
78
120
|
|
|
79
121
|
With `--output ndjson`, the CLI writes each array item as one JSON value on its
|
|
80
122
|
own line, without a wrapping array; a non-array result is one line.
|
|
81
123
|
|
|
124
|
+
With `--output csv`, quoting follows RFC 4180, and text that a spreadsheet would run as a formula (it starts with `=`,
|
|
125
|
+
`+`, `-`, `@`, the full-width form of one of them, a tab or a line break) gets a leading `'`. Every line break in a cell
|
|
126
|
+
is written as a line feed, and an empty cell that is alone on its line as `""`. `clk115 reports` prints the rows of a
|
|
127
|
+
report, one entry or group each; other commands print what Clockify answers, one line per record. `reports detailed`
|
|
128
|
+
reads one page, and warns when that page is full.
|
|
129
|
+
|
|
130
|
+
Output that cannot be written exits 1 with `fatal: the output could not be written`. A reader that closes the pipe
|
|
131
|
+
(`| head -1`) ends the command quietly, except where that would hide something: `batch` and `webhooks listen` stop and
|
|
132
|
+
exit 1.
|
|
133
|
+
|
|
82
134
|
In `json` and `ndjson` modes, errors go to stderr as `{"ok": false, "error":
|
|
83
135
|
"...", "code": "...", "recovery": "...", "retryable": true|false}`. An API
|
|
84
136
|
failure also carries `"status"` (the HTTP status) and, when Clockify returned
|
|
@@ -120,9 +172,10 @@ command to run before retrying.
|
|
|
120
172
|
`expenses list` prints a JSON array, one expense per NDJSON line, or a table.
|
|
121
173
|
Reaching `--limit` returns the requested prefix. Reaching `--max-pages` first
|
|
122
174
|
can leave matching expenses unexamined. In either case the command exits 0
|
|
123
|
-
and warns on stderr
|
|
124
|
-
|
|
125
|
-
|
|
175
|
+
and warns on stderr, or exits 1 with `--require-complete`. To continue, keep
|
|
176
|
+
the same filters and page size and append the printed
|
|
177
|
+
`--page N --offset M --max-pages K` flags. At the last supported page the
|
|
178
|
+
warning says when there is no further cursor.
|
|
126
179
|
|
|
127
180
|
Add `--with-meta` for machine-readable scan metadata. JSON then returns
|
|
128
181
|
`{"items":[…],"meta":{…}}`. NDJSON appends one final `{"meta":{…}}` line,
|
|
@@ -162,6 +215,20 @@ without unit conversion.
|
|
|
162
215
|
|---|---|
|
|
163
216
|
| `clk115 status` | Print workspace, current user, and running timer. |
|
|
164
217
|
| `clk115 doctor` | Check local CLI configuration without contacting Clockify. |
|
|
218
|
+
| `clk115 auth login` | Check an API key with Clockify, then keep it in the OS keychain under a profile. The key is read from stdin or a hidden prompt. |
|
|
219
|
+
| `clk115 auth status` | Show which credential is used, and check it with Clockify. |
|
|
220
|
+
| `clk115 auth list` | List the profiles and whether each has a key in the keychain. |
|
|
221
|
+
| `clk115 auth use <profile>` | Make a profile the current one. |
|
|
222
|
+
| `clk115 auth logout` | Delete a profile and its key from the keychain. |
|
|
223
|
+
| `clk115 auth exec -- <command…>` | Run a program with the selected credential in its environment. |
|
|
224
|
+
| `clk115 operations list [words…] [--effect effect] [--tag tag] [--limit N] [--all]` | Search the catalog of every public API operation. Needs no credentials. |
|
|
225
|
+
| `clk115 operations show <operation>` | Print the method, path, effect and input schema of an operation. Needs no credentials. |
|
|
226
|
+
| `clk115 operations call <operation> [-p key=value…] [-q key=value…] [--body json] [--file path] [--output-file path] [--dry-run]` | Call any operation. The input is checked against its schema before anything is sent. |
|
|
227
|
+
| `clk115 batch [@file\|-] [--on-error stop\|continue] [--concurrency N] [--max-requests N] [--dry-run]` | Run many operations from NDJSON rows. Every row is checked before the first request. |
|
|
228
|
+
| `clk115 commands` | List every command with its arguments, options and risk, for scripts and agents. |
|
|
229
|
+
| `clk115 skill list` | List the agent skills that come with this command line. |
|
|
230
|
+
| `clk115 skill show <name>` | Print an agent skill. |
|
|
231
|
+
| `clk115 skill install [names…] [--dir path] [--personal] [--force]` | Copy agent skills into a directory an agent reads. |
|
|
165
232
|
| `clk115 start [description] [-p project] [-t task] [--tag tag…] [--billable]` | Start a timer. Resolves project, task, and tag names to IDs. |
|
|
166
233
|
| `clk115 stop` | Stop the running timer for the current user. |
|
|
167
234
|
| `clk115 log <duration> <description> [-p project] [-t task] [--tag tag…] [--billable] [--end iso]` | Log a finished entry. Resolves project, task, and tag names to IDs. Duration accepts `1h30m`, `90m`, or `PT1H30M`. |
|
|
@@ -191,9 +258,13 @@ without unit conversion.
|
|
|
191
258
|
| `clk115 webhooks list [--type type]` | List outbound webhooks. |
|
|
192
259
|
| `clk115 webhooks create --name X --url U --event E [--trigger-source-type T --trigger-source ids]` | Create a webhook subscription. |
|
|
193
260
|
| `clk115 webhooks delete <id>` | Delete a webhook subscription. |
|
|
261
|
+
| `clk115 webhooks events` | List the event names a webhook can subscribe to. |
|
|
262
|
+
| `clk115 webhooks listen --webhook id\|--secret-stdin [--port N] [--forward url] [--max N]` | Receive deliveries on a loopback port, verify each one and print it as a JSON line. |
|
|
263
|
+
| `clk115 webhooks trigger <event> --data json --webhook id\|--secret-stdin [--url url]` | Send a signed delivery to a handler on this machine. |
|
|
264
|
+
| `clk115 webhooks recover <id> [--status FAILED\|RETRYING] [--forward url] [--limit N]` | List the deliveries of a webhook that Clockify could not complete, and optionally hand them to a local handler. |
|
|
194
265
|
| `clk115 invoices list [--limit N] [--page N]` | List invoices in the workspace. |
|
|
195
266
|
| `clk115 invoices create --client id --number N --currency USD --issued YYYY-MM-DD --due YYYY-MM-DD [--time-view-mode mode]` | Create an invoice draft. |
|
|
196
|
-
| `clk115 expenses list [--limit N] [--page-size N] [--max-pages N] [--page N] [--offset N] [--with-meta] [--start date] [--end date]` | List workspace expenses; date bounds are applied client-side across bounded pages. |
|
|
267
|
+
| `clk115 expenses list [--limit N] [--page-size N] [--max-pages N] [--page N] [--offset N] [--with-meta] [--require-complete] [--start date] [--end date]` | List workspace expenses; date bounds are applied client-side across bounded pages. |
|
|
197
268
|
| `clk115 expenses get <id>` | Get one expense by ID. |
|
|
198
269
|
| `clk115 expenses create --amount N --category id --date YYYY-MM-DD [--user id] [--project id] [--task id] [--notes text] [--billable\|--no-billable]` | Create an expense (scalar body; --user defaults to the API-key owner). |
|
|
199
270
|
| `clk115 expenses update <id> --amount N --category id --date YYYY-MM-DD --user id [--project id] [--task id] [--notes text] [--billable\|--no-billable]` | Update an expense (full replace of amount, category, date). |
|
|
@@ -220,7 +291,7 @@ without unit conversion.
|
|
|
220
291
|
| `clk115 users list [--limit N] [--page N] [--name text]` | List members of the workspace. Read-only. |
|
|
221
292
|
| `clk115 users invite <email> [--no-send-email]` | Invite (add) a user to the workspace by email. |
|
|
222
293
|
| `clk115 users update-profile <userId> [--name text] [--image-url url] [--remove-image] [--week-start day] [--work-capacity iso] [--working-days days…]` | Update one user's member profile. |
|
|
223
|
-
| `clk115 api <method> <path> [-q key=value…] [-H key=value…] [--body json\|@file\|-] [--all] [--page-size N] [--max-pages N] [--include-headers]` | Call a Clockify API path directly through the SDK client. Fills {workspaceId} from --workspace or CLOCKIFY_WORKSPACE_ID. |
|
|
294
|
+
| `clk115 api <method> <path> [-q key=value…] [-H key=value…] [--body json\|@file\|-] [--all] [--page-size N] [--max-pages N] [--require-complete] [--include-headers]` | Call a Clockify API path directly through the SDK client. Fills {workspaceId} from --workspace or CLOCKIFY_WORKSPACE_ID. |
|
|
224
295
|
| `clk115 approvals submit-with-type --type TIMESHEET\|EXPENSE --period-start date [--period WEEKLY\|SEMI_MONTHLY\|MONTHLY]` | Submit the current user's approval request with an explicit type. |
|
|
225
296
|
| `clk115 approvals submit-for-user-with-type --user id --type TIMESHEET\|EXPENSE\|TIMESHEET_AND_EXPENSE --period-start date [--period WEEKLY\|SEMI_MONTHLY\|MONTHLY]` | Submit another user's approval request with an explicit type. |
|
|
226
297
|
| `clk115 completion [zsh\|bash\|fish]` | Print a shell completion script for zsh, bash, or fish. |
|
|
@@ -255,8 +326,78 @@ List the 50 most recent entries, filtered by description:
|
|
|
255
326
|
clk115 entries list --limit 50 --description deploy
|
|
256
327
|
```
|
|
257
328
|
|
|
258
|
-
|
|
259
|
-
|
|
329
|
+
The scripts in [`examples/`](./examples) are ready to run with `CLOCKIFY_API_KEY` and `CLOCKIFY_WORKSPACE_ID` set:
|
|
330
|
+
`status.sh`, `list-projects.sh`, `log-time.sh [project]`, `daily-timesheet.sh [day]`, and `export-json.sh [directory]`,
|
|
331
|
+
which never leaves a partial export behind its final name. `mock-run.sh` needs no key: start `make mock-clockify` in the
|
|
332
|
+
repository first.
|
|
333
|
+
|
|
334
|
+
## Every operation
|
|
335
|
+
|
|
336
|
+
When no command fits, search the catalog of all public API operations, read the schema, and call it. `list` and `show`
|
|
337
|
+
need no credentials. The input of `call` is checked before anything is sent.
|
|
338
|
+
|
|
339
|
+
```sh
|
|
340
|
+
clk115 operations list archive a project
|
|
341
|
+
clk115 operations show projects.update --json
|
|
342
|
+
clk115 operations call tags.list -q archived=false --output csv --fields id,name
|
|
343
|
+
clk115 operations call tags.create --body '{"name":"focus"}' --dry-run
|
|
344
|
+
clk115 operations call invoices.export -p invoiceId=64c777ddd3fcab07cfbb210c -q userLocale=en-US --output-file invoice.pdf
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
A file goes to `--output-file`, which must not exist yet, or to a redirected stdout, byte for byte. `operations call`
|
|
348
|
+
and `batch` leave out a webhook's signing token, and show nothing of an answer that may hold one and is not JSON.
|
|
349
|
+
|
|
350
|
+
`clk115 commands --json` describes every command, with its options, defaults and risk: `read`, `local` (changes only
|
|
351
|
+
this machine), `write` or `destructive`.
|
|
352
|
+
|
|
353
|
+
## Batches
|
|
354
|
+
|
|
355
|
+
`batch` runs one operation per NDJSON row. Every row is checked before the first request, so one bad row means that
|
|
356
|
+
nothing is sent (exit 2).
|
|
357
|
+
|
|
358
|
+
```sh
|
|
359
|
+
echo '{"operation":"tags.create","body":{"name":"focus"},"id":"row-1"}' | clk115 batch --dry-run
|
|
360
|
+
clk115 batch @rows.ndjson --on-error continue > results.ndjson
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
Each row gets one result line with its `index`, `id`, `operation`, `outcome` and `data` or `error`:
|
|
364
|
+
|
|
365
|
+
| Outcome | Meaning |
|
|
366
|
+
|---|---|
|
|
367
|
+
| `ok` | Clockify answered with success. |
|
|
368
|
+
| `rejected` | Clockify refused the write. Nothing changed. |
|
|
369
|
+
| `unknown` | The write may have applied. Read the record back before you send the row again. |
|
|
370
|
+
| `failed` | A read failed. |
|
|
371
|
+
| `skipped` | The row was not sent. |
|
|
372
|
+
|
|
373
|
+
A row is sent again only after a 429, which changed nothing: up to three times, after the wait that Clockify asks for,
|
|
374
|
+
when that is at most a minute. A rate limit that outlasts this stops the batch. So does a write with an unknown outcome.
|
|
375
|
+
Both do so with `--on-error continue` too. Interrupting the batch (Ctrl-C, SIGTERM, or a terminal that closes) lets the
|
|
376
|
+
requests in flight finish. Interrupting it again gives them up, and a write that was given up is `unknown`. When the
|
|
377
|
+
output cannot be written the batch stops, and every result goes to stderr; so it does when nobody reads the output
|
|
378
|
+
within a second after the second interrupt. Each way, every row is reported. Requests run one at a time unless
|
|
379
|
+
`--concurrency` says otherwise (8 at most). `--max-requests` (1000) guards against a wrong file.
|
|
380
|
+
|
|
381
|
+
## Webhooks on this machine
|
|
382
|
+
|
|
383
|
+
`webhooks listen` verifies deliveries on a loopback port, prints each one as a JSON line, and can pass it to a local
|
|
384
|
+
handler. Clockify delivers to public `https://` URLs only, so put your own tunnel in front. A delivery that cannot be
|
|
385
|
+
printed or handed on is answered with 500, so that Clockify sends it again. `--max` counts what was printed. `--forward`
|
|
386
|
+
passes on the bytes that arrived. An interrupt finishes the deliveries that have arrived in full, and drops the others.
|
|
387
|
+
`webhooks trigger` sends a signed delivery to a local handler, and `webhooks recover` reads what Clockify could not
|
|
388
|
+
deliver in the last 7 days. The signing secret comes from Clockify (`--webhook`) or from stdin (`--secret-stdin`), and
|
|
389
|
+
goes to loopback addresses only.
|
|
390
|
+
|
|
391
|
+
## Agent skills
|
|
392
|
+
|
|
393
|
+
`clk115 skill install` copies the skills that come with this version to `.claude/skills` (`--personal` for your home,
|
|
394
|
+
`--dir` for another agent). It refuses a skill directory or a `SKILL.md` that is a symbolic link; the directories above
|
|
395
|
+
may be links. In Claude Code the skills and the MCP server also come as one plugin:
|
|
396
|
+
`/plugin install clockify115 --marketplace apet97/clockify-ts-sdk`.
|
|
397
|
+
|
|
398
|
+
## The raw API
|
|
399
|
+
|
|
400
|
+
Call a path directly through the SDK client:
|
|
260
401
|
|
|
261
402
|
```sh
|
|
262
403
|
clk115 api GET '/workspaces/{workspaceId}/tags' --query page-size=20 --output json
|
|
@@ -268,8 +409,9 @@ clk115 api POST '/workspaces/{workspaceId}/tags' --body '{"name":"billable"}' --
|
|
|
268
409
|
`--all` walks `page`/`page-size` until a short or empty page (bounded by
|
|
269
410
|
`--max-pages`), and `--body` also accepts `@file` or `-` for stdin. If the walk
|
|
270
411
|
stops because it hit `--max-pages`, the collection is incomplete and a `WARN`
|
|
271
|
-
line goes to **stderr**; stdout stays byte-identical either way
|
|
272
|
-
|
|
412
|
+
line goes to **stderr**; stdout stays byte-identical either way. A script that
|
|
413
|
+
must not continue with a partial collection adds `--require-complete`: the rows
|
|
414
|
+
are printed and the command exits 1.
|
|
273
415
|
|
|
274
416
|
An exact duplicate of the previous page stops the walk before adding its rows.
|
|
275
417
|
The warning identifies an endpoint that ignores pagination. Raw HTTP errors
|
|
@@ -309,14 +451,18 @@ clk115 completion fish > ~/.config/fish/completions/clk115.fish
|
|
|
309
451
|
With `--json` or `--output ndjson`, the completion script is one JSON string.
|
|
310
452
|
|
|
311
453
|
For a one-off in the current shell: `source <(clk115 completion bash)`. The
|
|
312
|
-
`clockify115` binary accepts the same subcommand.
|
|
313
|
-
scripts.
|
|
454
|
+
`clockify115` binary accepts the same subcommand.
|
|
314
455
|
|
|
315
456
|
## Exit codes
|
|
316
457
|
|
|
317
458
|
- `0` — success, including `--help` and `--version`
|
|
318
459
|
- `1` — runtime or API failure (missing credentials, HTTP errors, network failures)
|
|
319
|
-
- `2` — usage or local input validation error (unknown flag, missing required argument, invalid enum
|
|
460
|
+
- `2` — usage or local input validation error (unknown flag, missing required argument, invalid enum, date or filter). Nothing was changed: only reads, such as a name lookup, can have been sent before it.
|
|
461
|
+
|
|
462
|
+
`auth exec` exits as the program it ran, with `128` plus the signal number when a signal ended it. `batch`,
|
|
463
|
+
`webhooks recover` and `webhooks listen --max` exit with `129` (SIGHUP), `130` (SIGINT) or `143` (SIGTERM) exactly when
|
|
464
|
+
an interrupt cut their work short, and report what they did. Any other command that a signal ends prints nothing more: a
|
|
465
|
+
write that was in flight may have applied.
|
|
320
466
|
|
|
321
467
|
## Development
|
|
322
468
|
|
|
@@ -332,7 +478,7 @@ node dist/index.js status # smoke test (or invoke installed clk115/clockify11
|
|
|
332
478
|
```
|
|
333
479
|
|
|
334
480
|
`clockify-sdk-ts-115` is workspace-linked for local development and is a
|
|
335
|
-
`^
|
|
481
|
+
`^7.0.0` peer dependency for published consumers.
|
|
336
482
|
|
|
337
483
|
## License
|
|
338
484
|
|
package/dist/client.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isMutationCommand } from "./commands/leaf-command.js";
|
|
2
|
-
import {
|
|
2
|
+
import { missingApiKey } from "./config.js";
|
|
3
|
+
import { UsageError } from "./failure.js";
|
|
3
4
|
import { observeWriteTransport } from "./write-outcome.js";
|
|
4
5
|
export const REGIONAL_PREFIXES = ["eu", "us", "uk", "au"];
|
|
5
6
|
export const KNOWN_REGIONS = ["global", ...REGIONAL_PREFIXES, "developer"];
|
|
@@ -7,11 +8,11 @@ export function buildRoutingOptions(region, subdomain, baseUrl) {
|
|
|
7
8
|
if (region === undefined && subdomain === undefined)
|
|
8
9
|
return undefined;
|
|
9
10
|
if (baseUrl !== undefined) {
|
|
10
|
-
throw new
|
|
11
|
+
throw new UsageError("clk115: --region/--subdomain and --base-url configure the same thing two different ways; provide only one of them.");
|
|
11
12
|
}
|
|
12
13
|
if (subdomain !== undefined) {
|
|
13
14
|
if (region === undefined || !REGIONAL_PREFIXES.includes(region)) {
|
|
14
|
-
throw new
|
|
15
|
+
throw new UsageError(`--subdomain requires --region (got ${JSON.stringify(region)}). Provide one of: ${REGIONAL_PREFIXES.join(", ")}.`);
|
|
15
16
|
}
|
|
16
17
|
return {
|
|
17
18
|
profile: "subdomain",
|
|
@@ -23,7 +24,7 @@ export function buildRoutingOptions(region, subdomain, baseUrl) {
|
|
|
23
24
|
if (region === "global")
|
|
24
25
|
return { profile: "global" };
|
|
25
26
|
if (region === undefined || !KNOWN_REGIONS.includes(region)) {
|
|
26
|
-
throw new
|
|
27
|
+
throw new UsageError(`Unrecognized Clockify region ${JSON.stringify(region)}. Provide one of ${KNOWN_REGIONS.join(", ")}.`);
|
|
27
28
|
}
|
|
28
29
|
return {
|
|
29
30
|
profile: region,
|
|
@@ -36,15 +37,37 @@ export function unconfirmedRegionNotice(routing) {
|
|
|
36
37
|
const host = routing.profile === "subdomain" ? `${routing.subdomain} (${routing.region})` : routing.profile;
|
|
37
38
|
return `clk115: using the unconfirmed "${host}" Clockify profile. Only the global profile is live-confirmed; drop --region/--subdomain (and CLOCKIFY_REGION/CLOCKIFY_SUBDOMAIN or the rc-file entry) to route to api.clockify.me.`;
|
|
38
39
|
}
|
|
39
|
-
|
|
40
|
+
async function profileApiKey(config, store) {
|
|
41
|
+
const credentials = await import("./credentials.js");
|
|
42
|
+
return await credentials.storedApiKey(config, store ?? credentials.systemCredentialStore);
|
|
43
|
+
}
|
|
44
|
+
export function requireHeaderValue(apiKey) {
|
|
45
|
+
try {
|
|
46
|
+
new Headers().set("X-Api-Key", apiKey);
|
|
47
|
+
return apiKey;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
throw new UsageError("The API key has a character that no request header can carry. Provide the key exactly as Clockify shows it.");
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export async function buildClient(config, command, credentials) {
|
|
54
|
+
const apiKey = config.apiKey ?? (await profileApiKey(config, credentials));
|
|
55
|
+
if (apiKey === undefined)
|
|
56
|
+
throw missingApiKey(config);
|
|
40
57
|
const transport = command && isMutationCommand(command) ? observeWriteTransport(command) : undefined;
|
|
41
|
-
const { client, routing } = await createRoutedClient(config,
|
|
58
|
+
const { client, routing } = await createRoutedClient(config, requireHeaderValue(apiKey), transport);
|
|
42
59
|
const notice = unconfirmedRegionNotice(routing);
|
|
43
60
|
if (notice !== undefined)
|
|
44
61
|
process.stderr.write(`${notice}\n`);
|
|
45
62
|
return client;
|
|
46
63
|
}
|
|
47
|
-
|
|
64
|
+
const offline = () => {
|
|
65
|
+
throw new Error("This client only checks its route.");
|
|
66
|
+
};
|
|
67
|
+
export async function requireRoute(config) {
|
|
68
|
+
await createRoutedClient(config, offline);
|
|
69
|
+
}
|
|
70
|
+
async function createRoutedClient(config, apiKey, transport) {
|
|
48
71
|
const routing = buildRoutingOptions(config.region, config.subdomain, config.baseUrl);
|
|
49
72
|
const { createClockifyClient } = await import("clockify-sdk-ts-115");
|
|
50
73
|
const options = { apiKey, allowNonClockifyHttpsHost: false, ...(transport && { fetch: transport }) };
|
package/dist/commands/api.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { readFileSync } from "node:fs";
|
|
2
1
|
import { UsageError } from "../failure.js";
|
|
3
2
|
import { resolveFlags } from "../flags.js";
|
|
4
|
-
import { AlreadyReportedError,
|
|
3
|
+
import { AlreadyReportedError, printData } from "../output.js";
|
|
5
4
|
import { dispatchedWrite, writeFailure } from "../write-outcome.js";
|
|
6
|
-
import { parseIntArg, resolveBaseContext, rootProgram } from "./helpers.js";
|
|
5
|
+
import { collect, parseIntArg, parseJson, parsePair, printScan, readTextInput, resolveBaseContext, rootProgram } from "./helpers.js";
|
|
7
6
|
import { leafCommand } from "./leaf-command.js";
|
|
8
7
|
const METHODS = new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
9
8
|
const CREDENTIAL_HEADERS = new Set(["x-api-key", "x-addon-token"]);
|
|
@@ -23,9 +22,10 @@ export const registerApiCommand = (program, services) => {
|
|
|
23
22
|
.option("-q, --query <key=value>", "Query parameter (repeatable).", collect, [])
|
|
24
23
|
.option("-H, --header <key=value>", "Request header as key=value or 'Key: value' (repeatable).", collect, [])
|
|
25
24
|
.option("--body <json|@file|->", "JSON body: inline, @file, or - for stdin.")
|
|
26
|
-
.option("--all", "
|
|
25
|
+
.option("--all", "Read every page of a list, honoring Last-Page when present.", false)
|
|
27
26
|
.option("--page-size <n>", "Page size for --all.", parseIntArg, 50)
|
|
28
27
|
.option("--max-pages <n>", "Maximum pages for --all.", parseIntArg, 20)
|
|
28
|
+
.option("--require-complete", "Print the rows, then exit 1 unless --all is known to have read every page.", false)
|
|
29
29
|
.option("--include-headers", "Include status and response headers in output.", false)
|
|
30
30
|
.action(async function (methodArg, pathArg, options) {
|
|
31
31
|
const method = methodArg.toUpperCase();
|
|
@@ -36,12 +36,12 @@ export const registerApiCommand = (program, services) => {
|
|
|
36
36
|
const query = options.query.map((value) => parsePair(value, "--query"));
|
|
37
37
|
const headers = parseHeaders(options.header);
|
|
38
38
|
validatePagingFlags(this, method, options);
|
|
39
|
-
const body =
|
|
39
|
+
const body = await readTextInput(options.body, "--body");
|
|
40
40
|
if (body !== undefined && method === "GET") {
|
|
41
41
|
throw new UsageError("--body cannot be sent with GET; use POST, PUT, PATCH, or DELETE.");
|
|
42
42
|
}
|
|
43
43
|
if (body !== undefined && !hasHeader(headers, "content-type")) {
|
|
44
|
-
|
|
44
|
+
parseJson(body, "--body", "set a Content-Type header to send another format");
|
|
45
45
|
}
|
|
46
46
|
const output = resolveFlags(rootProgram(this));
|
|
47
47
|
const binaryConflict = process.stdout.isTTY || output.mode !== "table" || options.includeHeaders || options.all;
|
|
@@ -53,16 +53,15 @@ export const registerApiCommand = (program, services) => {
|
|
|
53
53
|
const path = resolvePath(pathArg, config.workspaceId);
|
|
54
54
|
if (options.all) {
|
|
55
55
|
const { items, stop } = await fetchAllPages(client, path, query, headers, options.pageSize, options.maxPages);
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
printApiOutput(items, output);
|
|
56
|
+
const gap = {
|
|
57
|
+
complete: undefined,
|
|
58
|
+
repeated: "The endpoint ignores pagination (repeated page); returning the preceding pages.",
|
|
59
|
+
truncated: `--all stopped at the --max-pages limit (${options.maxPages}); the results are incomplete. Re-run with a larger --max-pages.`,
|
|
60
|
+
}[stop];
|
|
61
|
+
printScan(() => { printData(items, output); }, gap, options.requireComplete, output);
|
|
63
62
|
return;
|
|
64
63
|
}
|
|
65
|
-
const request = client.fetch(
|
|
64
|
+
const request = client.fetch(path, requestInit(method, headers, body), queryParams(query));
|
|
66
65
|
const response = method === "GET" ? await request : await dispatchedWrite(this, request);
|
|
67
66
|
if (isBinaryResponse(response)) {
|
|
68
67
|
if (!response.ok || binaryConflict) {
|
|
@@ -76,7 +75,7 @@ export const registerApiCommand = (program, services) => {
|
|
|
76
75
|
}
|
|
77
76
|
if (response.ok) {
|
|
78
77
|
const data = await readResponseData(response);
|
|
79
|
-
|
|
78
|
+
printData(responsePayload(response, data, options.includeHeaders), output);
|
|
80
79
|
return;
|
|
81
80
|
}
|
|
82
81
|
const { data, readError } = await readErrorData(response);
|
|
@@ -95,25 +94,10 @@ export const registerApiCommand = (program, services) => {
|
|
|
95
94
|
const classified = classifyClockifyError(cause);
|
|
96
95
|
Object.assign(payload, { retryable: classified?.retryable, recovery: classified?.recovery }, write);
|
|
97
96
|
}
|
|
98
|
-
|
|
97
|
+
printData(payload, output);
|
|
99
98
|
throw new AlreadyReportedError();
|
|
100
99
|
});
|
|
101
100
|
};
|
|
102
|
-
function collect(value, previous) {
|
|
103
|
-
previous.push(value);
|
|
104
|
-
return previous;
|
|
105
|
-
}
|
|
106
|
-
function parsePair(value, flag) {
|
|
107
|
-
const index = value.indexOf("=");
|
|
108
|
-
if (index <= 0) {
|
|
109
|
-
throw new UsageError(`${flag} expected key=value, received "${value}".`);
|
|
110
|
-
}
|
|
111
|
-
const key = value.slice(0, index).trim();
|
|
112
|
-
if (!key) {
|
|
113
|
-
throw new UsageError(`${flag} expected a non-empty key in "${value}".`);
|
|
114
|
-
}
|
|
115
|
-
return [key, value.slice(index + 1)];
|
|
116
|
-
}
|
|
117
101
|
function parseHeaders(values) {
|
|
118
102
|
const headers = {};
|
|
119
103
|
for (const value of values) {
|
|
@@ -148,6 +132,7 @@ function validatePagingFlags(command, method, options) {
|
|
|
148
132
|
for (const [option, flag] of [
|
|
149
133
|
["pageSize", "--page-size"],
|
|
150
134
|
["maxPages", "--max-pages"],
|
|
135
|
+
["requireComplete", "--require-complete"],
|
|
151
136
|
]) {
|
|
152
137
|
if (command.getOptionValueSource(option) === "cli") {
|
|
153
138
|
throw new UsageError(`${flag} only applies with --all; for a single page pass -q page-size=N instead.`);
|
|
@@ -162,15 +147,6 @@ function validatePagingFlags(command, method, options) {
|
|
|
162
147
|
throw new UsageError("--include-headers is not supported with --all; each page's status and headers are consumed by the pagination walk.");
|
|
163
148
|
}
|
|
164
149
|
}
|
|
165
|
-
function requireJson(body) {
|
|
166
|
-
try {
|
|
167
|
-
JSON.parse(body);
|
|
168
|
-
}
|
|
169
|
-
catch (err) {
|
|
170
|
-
const detail = err instanceof Error ? err.message : String(err);
|
|
171
|
-
throw new UsageError(`--body is not valid JSON (${detail}); provide valid JSON, or set a Content-Type header to send another format.`);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
150
|
function resolvePath(path, workspaceId) {
|
|
175
151
|
if (path.includes("{workspaceId}")) {
|
|
176
152
|
if (!workspaceId) {
|
|
@@ -180,16 +156,11 @@ function resolvePath(path, workspaceId) {
|
|
|
180
156
|
}
|
|
181
157
|
return path;
|
|
182
158
|
}
|
|
183
|
-
function
|
|
184
|
-
const
|
|
185
|
-
const base = qIndex === -1 ? path : path.slice(0, qIndex);
|
|
186
|
-
const params = new URLSearchParams(qIndex === -1 ? "" : path.slice(qIndex + 1));
|
|
187
|
-
for (const key of new Set(query.map(([name]) => name)))
|
|
188
|
-
params.delete(key);
|
|
159
|
+
function queryParams(query) {
|
|
160
|
+
const params = {};
|
|
189
161
|
for (const [key, value] of query)
|
|
190
|
-
params.
|
|
191
|
-
|
|
192
|
-
return search ? `${base}?${search}` : base;
|
|
162
|
+
(params[key] ??= []).push(value);
|
|
163
|
+
return { queryParams: params };
|
|
193
164
|
}
|
|
194
165
|
function requestInit(method, headers, body) {
|
|
195
166
|
const merged = { ...headers };
|
|
@@ -202,35 +173,39 @@ function requestInit(method, headers, body) {
|
|
|
202
173
|
}
|
|
203
174
|
return init;
|
|
204
175
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
176
|
+
const PAGE_SIZE_NAMES = ["page-size", "pageSize", "size", "limit"];
|
|
177
|
+
const LARGEST_PAGE = 200;
|
|
178
|
+
async function pagingOf(path) {
|
|
179
|
+
const { operations } = await import("clockify-sdk-ts-115/operations");
|
|
180
|
+
const segments = path.split("?", 1)[0]?.split("/") ?? [];
|
|
181
|
+
for (const operation of operations().values()) {
|
|
182
|
+
const { page, ...query } = operation.input.properties?.query?.properties ?? {};
|
|
183
|
+
const sizeName = PAGE_SIZE_NAMES.find((name) => name in query);
|
|
184
|
+
const template = operation.path.split("/");
|
|
185
|
+
if (operation.method === "GET" &&
|
|
186
|
+
page &&
|
|
187
|
+
sizeName &&
|
|
188
|
+
template.length === segments.length &&
|
|
189
|
+
template.every((part, index) => part.startsWith("{") || part === segments[index])) {
|
|
190
|
+
return { first: Number(page.default ?? 1), sizeName };
|
|
217
191
|
}
|
|
218
192
|
}
|
|
219
|
-
return
|
|
193
|
+
return { first: 1, sizeName: "page-size" };
|
|
220
194
|
}
|
|
221
195
|
async function fetchAllPages(client, path, query, headers, pageSize, maxPages) {
|
|
222
196
|
const items = [];
|
|
223
|
-
const
|
|
224
|
-
|
|
197
|
+
const { first, sizeName } = await pagingOf(path);
|
|
198
|
+
const callerQuery = query.filter(([key]) => key !== "page" && key !== sizeName);
|
|
199
|
+
let state = { kind: "walking", page: first };
|
|
225
200
|
let previousPage;
|
|
226
201
|
while (state.kind === "walking") {
|
|
227
202
|
const page = state.page;
|
|
228
|
-
const
|
|
203
|
+
const paged = queryParams([
|
|
229
204
|
...callerQuery,
|
|
230
205
|
["page", String(page)],
|
|
231
|
-
[
|
|
206
|
+
[sizeName, String(pageSize)],
|
|
232
207
|
]);
|
|
233
|
-
const response = await client.fetch(
|
|
208
|
+
const response = await client.fetch(path, requestInit("GET", headers), paged);
|
|
234
209
|
if (isBinaryResponse(response)) {
|
|
235
210
|
await response.body?.cancel().catch(() => undefined);
|
|
236
211
|
if (!response.ok)
|
|
@@ -255,10 +230,10 @@ async function fetchAllPages(client, path, query, headers, pageSize, maxPages) {
|
|
|
255
230
|
items.push(...data);
|
|
256
231
|
if (data.length === 0 ||
|
|
257
232
|
lastPage === true ||
|
|
258
|
-
(lastPage === undefined && data.length < pageSize)) {
|
|
233
|
+
(lastPage === undefined && data.length < Math.min(pageSize, LARGEST_PAGE))) {
|
|
259
234
|
state = { kind: "complete" };
|
|
260
235
|
}
|
|
261
|
-
else if (page >= maxPages) {
|
|
236
|
+
else if (page - first + 1 >= maxPages) {
|
|
262
237
|
state = { kind: "truncated" };
|
|
263
238
|
}
|
|
264
239
|
else {
|
|
@@ -325,10 +300,3 @@ function responsePayload(response, data, includeHeaders) {
|
|
|
325
300
|
data,
|
|
326
301
|
};
|
|
327
302
|
}
|
|
328
|
-
function printApiOutput(value, output) {
|
|
329
|
-
if (output.mode === "ndjson") {
|
|
330
|
-
printNdjson(value, output);
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
printJson(value, output);
|
|
334
|
-
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { typedApprovalRequest } from "clockify-sdk-ts-115/requests";
|
|
1
2
|
import { UsageError } from "../failure.js";
|
|
2
3
|
import { printReceipt } from "../receipt.js";
|
|
3
4
|
import { dispatchedWrite } from "../write-outcome.js";
|
|
@@ -40,11 +41,7 @@ export const registerApprovalsCommand = (program, services) => {
|
|
|
40
41
|
if (opts.period)
|
|
41
42
|
body.period = requireEnum(opts.period, PERIODS, "period");
|
|
42
43
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
43
|
-
const created = await dispatchedWrite(this, client.approvals.submitWithType({
|
|
44
|
-
workspaceId,
|
|
45
|
-
approvalRequestId: type,
|
|
46
|
-
body,
|
|
47
|
-
}));
|
|
44
|
+
const created = await dispatchedWrite(this, client.approvals.submitWithType(typedApprovalRequest({ workspaceId, type, body })));
|
|
48
45
|
const data = approvalReceiptData(created);
|
|
49
46
|
printReceipt({
|
|
50
47
|
ok: true,
|