@apet97/clockify-cli-115 0.4.0 → 0.6.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 +32 -15
- package/dist/client.js +3 -3
- package/dist/commands/api.js +26 -20
- package/dist/commands/approvals.js +95 -0
- package/dist/commands/auditlog.js +13 -9
- package/dist/commands/balanceAssignment.js +149 -0
- package/dist/commands/clients.js +2 -2
- package/dist/commands/doctor.js +21 -4
- package/dist/commands/entries.js +28 -3
- package/dist/commands/helpers.js +9 -2
- package/dist/commands/invoices.js +22 -13
- package/dist/commands/log.js +1 -1
- package/dist/commands/projects.js +19 -1
- package/dist/commands/reports.js +24 -9
- package/dist/commands/resolve-refs.js +2 -2
- package/dist/commands/scheduling.js +2 -2
- package/dist/commands/sharedReports.js +41 -19
- package/dist/commands/start.js +0 -6
- package/dist/commands/stop.js +9 -2
- package/dist/commands/tags.js +3 -0
- package/dist/commands/tasks.js +8 -4
- package/dist/commands/timeoff.js +12 -5
- package/dist/commands/users.js +33 -9
- package/dist/commands/webhooks.js +6 -6
- package/dist/completions.js +1 -0
- package/dist/config.js +15 -14
- package/dist/duration.js +3 -3
- package/dist/generated/version.js +1 -1
- package/dist/index.js +30 -7
- package/package.json +5 -5
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
|
-
Current release: `0.
|
|
7
|
-
`clockify-sdk-ts-115 >=0.
|
|
6
|
+
Current release: `0.6.0`. Requires Node.js `>=22.13.0` and
|
|
7
|
+
`clockify-sdk-ts-115 >=0.13.0 <1`.
|
|
8
8
|
|
|
9
9
|
Two binaries, identical behavior:
|
|
10
10
|
|
|
@@ -12,6 +12,8 @@ Two binaries, identical behavior:
|
|
|
12
12
|
- `clk115` — short alias
|
|
13
13
|
|
|
14
14
|
```sh
|
|
15
|
+
npm ci && make sdk-codegen # from the repo root, once
|
|
16
|
+
npm run build -w clockify-sdk-ts-115 # build the workspace-linked SDK
|
|
15
17
|
cd cli
|
|
16
18
|
npm install
|
|
17
19
|
npm run build
|
|
@@ -34,13 +36,15 @@ In precedence order (highest wins):
|
|
|
34
36
|
2. **Environment variables:** `CLOCKIFY_API_KEY`, `CLOCKIFY_WORKSPACE_ID`,
|
|
35
37
|
optional `CLOCKIFY_BASE_URL` for mock/replay or private gateway tests,
|
|
36
38
|
optional `CLOCKIFY_REGION`/`CLOCKIFY_SUBDOMAIN` for regional routing
|
|
37
|
-
3. **Rc file:**
|
|
38
|
-
`$CLOCKIFY_HOME`
|
|
39
|
+
3. **Rc file:** `clockifyrc.json`, then `.clockifyrc.json`, both looked up in
|
|
40
|
+
`$CLOCKIFY_HOME` when it is set and in your home directory otherwise
|
|
39
41
|
|
|
40
42
|
`--region` (`global`, `eu`, `us`, `uk`, `au`, or `developer`) selects a Clockify
|
|
41
43
|
routing profile; `--subdomain` selects a workspace subdomain and requires
|
|
42
44
|
`--region` to be `eu`/`us`/`uk`/`au`. Both are mutually exclusive with
|
|
43
|
-
`--base-url`/`CLOCKIFY_BASE_URL`.
|
|
45
|
+
`--base-url`/`CLOCKIFY_BASE_URL`. Only the `global` profile is live-confirmed;
|
|
46
|
+
naming any other region is itself the acknowledgement that its route is
|
|
47
|
+
unproven for data residency.
|
|
44
48
|
|
|
45
49
|
Rc file shape:
|
|
46
50
|
|
|
@@ -69,7 +73,8 @@ touching production credentials.
|
|
|
69
73
|
- **`--select <path>`:** print a dot-path (e.g. `--select data.id` or
|
|
70
74
|
`--select 0.name`) before emitting JSON or NDJSON.
|
|
71
75
|
|
|
72
|
-
|
|
76
|
+
In `json` and `ndjson` modes, errors go to stderr as `{"ok": false, "error":
|
|
77
|
+
"...", "code": "...", "recovery": "...", "retryable": true|false}`; success-only
|
|
73
78
|
commands emit `{"ok": true, "message": "..."}`. `--no-color` disables ANSI
|
|
74
79
|
codes, and the CLI also auto-disables color when stdout is not a TTY.
|
|
75
80
|
Successful write commands in JSON and NDJSON include receipt fields:
|
|
@@ -87,6 +92,7 @@ Legacy top-level fields such as `id` remain for simple shell scripts.
|
|
|
87
92
|
| `clk115 stop` | Stop the running timer for the current user. |
|
|
88
93
|
| `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`. |
|
|
89
94
|
| `clk115 entries list [--limit N] [--page N] [--from YYYY-MM-DD] [--to YYYY-MM-DD] [--description text]` | List time entries for the current user. |
|
|
95
|
+
| `clk115 entries get-many --ids id1,id2 [--hydrated]` | Look up several time entries by ID in one call. |
|
|
90
96
|
| `clk115 entries delete <id>` | Delete a time entry. |
|
|
91
97
|
| `clk115 projects list [--limit N] [--page N] [--name text] [--archived] [--client id]` | List projects. |
|
|
92
98
|
| `clk115 projects create <name> [--client id] [--color hex] [--billable]` | Create a project. |
|
|
@@ -111,7 +117,7 @@ Legacy top-level fields such as `id` remain for simple shell scripts.
|
|
|
111
117
|
| `clk115 webhooks list [--type type]` | List outbound webhooks. |
|
|
112
118
|
| `clk115 webhooks create --name X --url U --event E [--trigger-source-type T --trigger-source ids]` | Create a webhook subscription. |
|
|
113
119
|
| `clk115 webhooks delete <id>` | Delete a webhook subscription. |
|
|
114
|
-
| `clk115 invoices list` | List invoices in the workspace. |
|
|
120
|
+
| `clk115 invoices list [--limit N] [--page N]` | List invoices in the workspace. |
|
|
115
121
|
| `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. |
|
|
116
122
|
| `clk115 expenses list [--limit N] [--page-size N] [--max-pages N] [--page N] [--start date] [--end date]` | List workspace expenses; date bounds are applied client-side across bounded pages. |
|
|
117
123
|
| `clk115 expenses get <id>` | Get one expense by ID. |
|
|
@@ -120,23 +126,29 @@ Legacy top-level fields such as `id` remain for simple shell scripts.
|
|
|
120
126
|
| `clk115 expenses delete <id>` | Delete an expense. |
|
|
121
127
|
| `clk115 timeoff list [--page N] [--limit N] [--start date] [--end date] [--status APPROVED,PENDING,…] [--user ids]` | List time-off requests. |
|
|
122
128
|
| `clk115 timeoff submit --policy id --start date (--end date \| --days N) [--note text] [--half-day --half-day-period FIRST_HALF\|SECOND_HALF]` | Submit a time-off request against a policy. Provide --end (HOURS-unit policies) or --days (DAYS-unit policies). |
|
|
123
|
-
| `clk115
|
|
129
|
+
| `clk115 timeoff balance-assignment list --user id --policy id` | List a user's balance assignments for one policy. |
|
|
130
|
+
| `clk115 timeoff balance-assignment create --policy id --user ids --balance amount [--note text] [--start YYYY-MM-DD] [--end YYYY-MM-DD]` | Add balance for one or more users on a policy. The API adds to an existing assignment and creates one when absent. |
|
|
131
|
+
| `clk115 timeoff balance-assignment update --id id --user id --policy id --change amount [--note text] [--start YYYY-MM-DD] [--end YYYY-MM-DD]` | Apply a balance delta to one assignment. The change adds to the current balance. |
|
|
132
|
+
| `clk115 timeoff balance-assignment delete --id id --user id --policy id --note text` | Delete a balance assignment. The API requires a note. |
|
|
133
|
+
| `clk115 scheduling list --from date --to date [--limit N] [--page N] [--name text]` | List scheduling assignments. |
|
|
124
134
|
| `clk115 scheduling create --user id --project id --start date --end date --hours-per-day N [--task id --note text --billable --include-non-working-days --publish]` | Create a scheduling assignment. Drafts by default; pass `--publish` to publish. |
|
|
125
135
|
| `clk115 audit-log search --start RFC3339 --end RFC3339 --actions A,B,… [--authors ids --authors-mode CONTAINS\|DOES_NOT_CONTAIN --page N --limit N]` | Search the workspace audit log. Window must be ≤ 31 days. |
|
|
126
136
|
| `clk115 reports summary [--period p] [--from date] [--to date] [--groups PROJECT,TASK] [--billable] [--project name\|id…] [--client name\|id…]` | Summary report totals over a date range, grouped per --groups. Read-only. |
|
|
127
137
|
| `clk115 reports detailed [--period p] [--from date] [--to date] [--page N] [--page-size N]` | Detailed report listing individual time entries over a date range. Read-only. |
|
|
128
|
-
| `clk115 reports weekly [--period p] [--from date] [--to date] [--group USER\|PROJECT] [--subgroup TIME]` | Weekly report
|
|
138
|
+
| `clk115 reports weekly [--period p] [--from date] [--to date] [--group USER\|PROJECT] [--subgroup TIME]` | Weekly report over exactly one seven-calendar-day window. Read-only. |
|
|
129
139
|
| `clk115 reports attendance [--period p] [--from date] [--to date]` | Attendance report of clock-in/out activity over a date range. Read-only. |
|
|
130
140
|
| `clk115 shared-reports list` | List the workspace's shared (public-link) reports. Read-only. |
|
|
131
|
-
| `clk115 shared-reports view <id> [--export-type JSON_V1\|JSON\|CSV
|
|
132
|
-
| `clk115 shared-reports create --name X --type T --filter json [--public]` | Create a shared (public-link) report. |
|
|
133
|
-
| `clk115 shared-reports update <id> --name X --type T --filter json [--public]` | Replace a shared report by ID (full replace of name, type, and filter). |
|
|
141
|
+
| `clk115 shared-reports view <id> [--export-type JSON_V1\|JSON\|CSV]` | View a shared report's text-safe rendered data by ID (not workspace-scoped). XLSX/PDF are rejected before the request until output-file streaming exists. Read-only. |
|
|
142
|
+
| `clk115 shared-reports create --name X --type T --filter json [--public\|--no-public]` | Create a shared (public-link) report. |
|
|
143
|
+
| `clk115 shared-reports update <id> --name X --type T --filter json [--public\|--no-public]` | Replace a shared report by ID (full replace of name, type, and filter). |
|
|
134
144
|
| `clk115 shared-reports delete <id>` | Delete a shared report. |
|
|
135
145
|
| `clk115 users me` | Show the current authenticated user (the API-key owner). Read-only. |
|
|
136
146
|
| `clk115 users list [--limit N] [--page N] [--name text]` | List members of the workspace. Read-only. |
|
|
137
147
|
| `clk115 users invite <email> [--no-send-email]` | Invite (add) a user to the workspace by email. |
|
|
138
148
|
| `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. |
|
|
139
149
|
| `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. |
|
|
150
|
+
| `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. |
|
|
151
|
+
| `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. |
|
|
140
152
|
| `clk115 completion [zsh\|bash\|fish]` | Print a shell completion script for zsh, bash, or fish. |
|
|
141
153
|
| `clk115 help [command]` | Print per-command help. |
|
|
142
154
|
| `clk115 --version` | Print CLI version. |
|
|
@@ -180,7 +192,10 @@ clk115 api POST '/workspaces/{workspaceId}/tags' --body '{"name":"billable"}' --
|
|
|
180
192
|
|
|
181
193
|
`{workspaceId}` is filled from `--workspace` or `CLOCKIFY_WORKSPACE_ID`.
|
|
182
194
|
`--all` walks `page`/`page-size` until a short or empty page (bounded by
|
|
183
|
-
`--max-pages`), and `--body` also accepts `@file` or `-` for stdin.
|
|
195
|
+
`--max-pages`), and `--body` also accepts `@file` or `-` for stdin. If the walk
|
|
196
|
+
stops because it hit `--max-pages`, the collection is incomplete and a `WARN`
|
|
197
|
+
line goes to **stderr**; stdout stays byte-identical either way, so pipelines
|
|
198
|
+
are unaffected and a script can detect truncation without parsing output.
|
|
184
199
|
|
|
185
200
|
## Shell completion
|
|
186
201
|
|
|
@@ -213,7 +228,9 @@ scripts.
|
|
|
213
228
|
|
|
214
229
|
```sh
|
|
215
230
|
git clone https://github.com/apet97/clockify-ts-sdk
|
|
216
|
-
cd clockify-ts-sdk
|
|
231
|
+
cd clockify-ts-sdk && npm ci && make sdk-codegen # populate the gitignored generated SDK sources
|
|
232
|
+
npm run build -w clockify-sdk-ts-115 # build the workspace-linked SDK
|
|
233
|
+
cd cli
|
|
217
234
|
npm install
|
|
218
235
|
npm run dev -- status # via tsx, no build needed
|
|
219
236
|
npm test # unit tests across duration / config / output / CLI contract / mock server
|
|
@@ -222,7 +239,7 @@ node dist/index.js status # smoke test (or invoke installed clk115/clockify11
|
|
|
222
239
|
```
|
|
223
240
|
|
|
224
241
|
`clockify-sdk-ts-115` is workspace-linked for local development and is a
|
|
225
|
-
`>=0.
|
|
242
|
+
`>=0.13.0 <1` peer dependency for published consumers.
|
|
226
243
|
|
|
227
244
|
## License
|
|
228
245
|
|
package/dist/client.js
CHANGED
|
@@ -6,7 +6,7 @@ export function buildRoutingOptions(region, subdomain) {
|
|
|
6
6
|
return undefined;
|
|
7
7
|
if (subdomain !== undefined) {
|
|
8
8
|
if (region === undefined || !REGIONAL_PREFIXES.includes(region)) {
|
|
9
|
-
throw new Error(`--subdomain requires --region
|
|
9
|
+
throw new Error(`--subdomain requires --region (got ${JSON.stringify(region)}). Provide one of: ${REGIONAL_PREFIXES.join(", ")}.`);
|
|
10
10
|
}
|
|
11
11
|
return {
|
|
12
12
|
profile: "subdomain",
|
|
@@ -18,7 +18,7 @@ export function buildRoutingOptions(region, subdomain) {
|
|
|
18
18
|
if (region === "global")
|
|
19
19
|
return { profile: "global" };
|
|
20
20
|
if (!KNOWN_REGIONS.includes(region)) {
|
|
21
|
-
throw new Error(`Unrecognized Clockify region ${JSON.stringify(region)}.
|
|
21
|
+
throw new Error(`Unrecognized Clockify region ${JSON.stringify(region)}. Provide one of ${KNOWN_REGIONS.join(", ")}.`);
|
|
22
22
|
}
|
|
23
23
|
return {
|
|
24
24
|
profile: region,
|
|
@@ -29,7 +29,7 @@ export async function buildClient(config) {
|
|
|
29
29
|
const apiKey = requireApiKey(config);
|
|
30
30
|
const routing = buildRoutingOptions(config.region, config.subdomain);
|
|
31
31
|
if (routing !== undefined && config.baseUrl !== undefined) {
|
|
32
|
-
throw new Error("clk115:
|
|
32
|
+
throw new Error("clk115: --region/--subdomain and --base-url configure the same thing two different ways; provide only one of them.");
|
|
33
33
|
}
|
|
34
34
|
const { createClockifyClient } = await import("clockify-sdk-ts-115");
|
|
35
35
|
if (routing !== undefined) {
|
package/dist/commands/api.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
|
+
import pc from "picocolors";
|
|
2
3
|
import { printJson, printNdjson } from "../output.js";
|
|
3
|
-
import { resolveBaseContext } from "./helpers.js";
|
|
4
|
+
import { parseIntArg, resolveBaseContext } from "./helpers.js";
|
|
4
5
|
import { leafCommand } from "./leaf-command.js";
|
|
5
6
|
const METHODS = new Set(["GET", "POST", "PUT", "PATCH", "DELETE"]);
|
|
6
7
|
export const registerApiCommand = (program, services) => {
|
|
@@ -12,14 +13,14 @@ export const registerApiCommand = (program, services) => {
|
|
|
12
13
|
.option("-H, --header <key=value>", "Request header (repeatable).", collect, [])
|
|
13
14
|
.option("--body <json|@file|->", "JSON body: inline, @file, or - for stdin.")
|
|
14
15
|
.option("--all", "Walk page/page-size pagination, honoring Last-Page when present.", false)
|
|
15
|
-
.option("--page-size <n>", "Page size for --all.",
|
|
16
|
-
.option("--max-pages <n>", "Maximum pages for --all.",
|
|
16
|
+
.option("--page-size <n>", "Page size for --all.", parseIntArg, 50)
|
|
17
|
+
.option("--max-pages <n>", "Maximum pages for --all.", parseIntArg, 20)
|
|
17
18
|
.option("--include-headers", "Include status and response headers in output.", false)
|
|
18
19
|
.action(async function (methodArg, pathArg, options) {
|
|
19
20
|
const { client, config, output } = await resolveBaseContext(this, services);
|
|
20
21
|
const method = methodArg.toUpperCase();
|
|
21
22
|
if (!METHODS.has(method)) {
|
|
22
|
-
throw new Error(`Unsupported method "${methodArg}".
|
|
23
|
+
throw new Error(`Unsupported method "${methodArg}". Provide one of: GET, POST, PUT, PATCH, DELETE.`);
|
|
23
24
|
}
|
|
24
25
|
const path = resolvePath(pathArg, config.workspaceId);
|
|
25
26
|
const query = parsePairs(options.query);
|
|
@@ -28,9 +29,14 @@ export const registerApiCommand = (program, services) => {
|
|
|
28
29
|
if (method !== "GET") {
|
|
29
30
|
throw new Error("--all is only supported for GET requests.");
|
|
30
31
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
if (options.includeHeaders) {
|
|
33
|
+
throw new Error("--include-headers is not supported with --all; each page's status and headers are consumed by the pagination walk.");
|
|
34
|
+
}
|
|
35
|
+
const { items, truncated } = await fetchAllPages(client, path, query, headers, options.pageSize, options.maxPages);
|
|
36
|
+
if (truncated) {
|
|
37
|
+
const prefix = output.color ? pc.yellow("WARN") : "WARN";
|
|
38
|
+
console.error(`${prefix} --all stopped at the --max-pages limit (${options.maxPages}); the results are incomplete. Re-run with a larger --max-pages.`);
|
|
39
|
+
}
|
|
34
40
|
printApiOutput(items, output);
|
|
35
41
|
return;
|
|
36
42
|
}
|
|
@@ -100,23 +106,21 @@ function readBody(body) {
|
|
|
100
106
|
if (body === undefined) {
|
|
101
107
|
return undefined;
|
|
102
108
|
}
|
|
103
|
-
if (body === "-") {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
109
|
+
if (body === "-" || body.startsWith("@")) {
|
|
110
|
+
const source = body === "-" ? 0 : body.slice(1);
|
|
111
|
+
try {
|
|
112
|
+
return readFileSync(source, "utf8");
|
|
113
|
+
}
|
|
114
|
+
catch (err) {
|
|
115
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
116
|
+
throw new Error(`--body ${JSON.stringify(body)} could not be read: ${detail}; provide a readable JSON file path or pipe the body on stdin`);
|
|
117
|
+
}
|
|
108
118
|
}
|
|
109
119
|
return body;
|
|
110
120
|
}
|
|
111
|
-
function parsePositiveInteger(value, flag) {
|
|
112
|
-
const parsed = Number(value);
|
|
113
|
-
if (!Number.isInteger(parsed) || parsed <= 0) {
|
|
114
|
-
throw new Error(`${flag} must be a positive integer.`);
|
|
115
|
-
}
|
|
116
|
-
return parsed;
|
|
117
|
-
}
|
|
118
121
|
async function fetchAllPages(client, path, query, headers, pageSize, maxPages) {
|
|
119
122
|
const items = [];
|
|
123
|
+
let truncated = true;
|
|
120
124
|
for (let page = 1; page <= maxPages; page += 1) {
|
|
121
125
|
const pagePath = buildPath(path, { ...query, page: String(page), "page-size": String(pageSize) });
|
|
122
126
|
const response = await client.fetch(pagePath, requestInit("GET", headers));
|
|
@@ -132,16 +136,18 @@ async function fetchAllPages(client, path, query, headers, pageSize, maxPages) {
|
|
|
132
136
|
const lastPage = parseLastPageHeader(response.headers.get("Last-Page"));
|
|
133
137
|
items.push(...data);
|
|
134
138
|
if (lastPage === true) {
|
|
139
|
+
truncated = false;
|
|
135
140
|
break;
|
|
136
141
|
}
|
|
137
142
|
if (lastPage === false) {
|
|
138
143
|
continue;
|
|
139
144
|
}
|
|
140
145
|
if (data.length === 0 || data.length < pageSize) {
|
|
146
|
+
truncated = false;
|
|
141
147
|
break;
|
|
142
148
|
}
|
|
143
149
|
}
|
|
144
|
-
return items;
|
|
150
|
+
return { items, truncated };
|
|
145
151
|
}
|
|
146
152
|
function parseLastPageHeader(value) {
|
|
147
153
|
if (value == null)
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { printReceipt } from "../receipt.js";
|
|
2
|
+
import { resolveContext } from "./helpers.js";
|
|
3
|
+
import { leafCommand } from "./leaf-command.js";
|
|
4
|
+
const PERIODS = ["WEEKLY", "SEMI_MONTHLY", "MONTHLY"];
|
|
5
|
+
const SELF_TYPES = ["TIMESHEET", "EXPENSE"];
|
|
6
|
+
const OTHER_TYPES = ["TIMESHEET", "EXPENSE", "TIMESHEET_AND_EXPENSE"];
|
|
7
|
+
function requireEnum(value, allowed, flag) {
|
|
8
|
+
const upper = value.toUpperCase();
|
|
9
|
+
const match = allowed.find((candidate) => candidate === upper);
|
|
10
|
+
if (!match) {
|
|
11
|
+
throw new Error(`--${flag} must be one of: ${allowed.join(", ")} (got ${JSON.stringify(value)}).`);
|
|
12
|
+
}
|
|
13
|
+
return match;
|
|
14
|
+
}
|
|
15
|
+
function approvalReceiptData(created) {
|
|
16
|
+
return {
|
|
17
|
+
id: created.id ?? "",
|
|
18
|
+
user: created.owner?.userId ?? "",
|
|
19
|
+
type: created.type ?? "",
|
|
20
|
+
status: created.status?.state ?? "",
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
export const registerApprovalsCommand = (program, services) => {
|
|
24
|
+
const approvals = program.command("approvals").description("Approval requests.");
|
|
25
|
+
leafCommand(approvals, "submit-with-type", "write")
|
|
26
|
+
.description("Submit the current user's approval request with an explicit type.")
|
|
27
|
+
.requiredOption("--type <type>", "Approval request type: TIMESHEET or EXPENSE.")
|
|
28
|
+
.requiredOption("--period-start <date>", "Approval period start (RFC3339).")
|
|
29
|
+
.option("--period <period>", "Approval period: WEEKLY, SEMI_MONTHLY, or MONTHLY.")
|
|
30
|
+
.action(async function (opts) {
|
|
31
|
+
const type = requireEnum(opts.type, SELF_TYPES, "type");
|
|
32
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
33
|
+
const body = {
|
|
34
|
+
periodStart: opts.periodStart,
|
|
35
|
+
};
|
|
36
|
+
if (opts.period)
|
|
37
|
+
body.period = requireEnum(opts.period, PERIODS, "period");
|
|
38
|
+
const created = await client.approvals.submitWithType({
|
|
39
|
+
workspaceId,
|
|
40
|
+
approvalRequestId: type,
|
|
41
|
+
body,
|
|
42
|
+
});
|
|
43
|
+
const data = approvalReceiptData(created);
|
|
44
|
+
printReceipt({
|
|
45
|
+
ok: true,
|
|
46
|
+
action: "approvals.submit-with-type",
|
|
47
|
+
entity: "approval_request",
|
|
48
|
+
ids: { approvalRequestId: data.id },
|
|
49
|
+
data,
|
|
50
|
+
changed: { created: [{ type: "approval_request", id: data.id }] },
|
|
51
|
+
next: [
|
|
52
|
+
{
|
|
53
|
+
command: "clk115 api GET /workspaces/{workspaceId}/approval-requests --json",
|
|
54
|
+
reason: "Review the submitted request.",
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
}, output);
|
|
58
|
+
});
|
|
59
|
+
leafCommand(approvals, "submit-for-user-with-type", "write")
|
|
60
|
+
.description("Submit another user's approval request with an explicit type.")
|
|
61
|
+
.requiredOption("--user <id>", "User ID whose approval request is submitted.")
|
|
62
|
+
.requiredOption("--type <type>", "Approval request type: TIMESHEET, EXPENSE, or TIMESHEET_AND_EXPENSE.")
|
|
63
|
+
.requiredOption("--period-start <date>", "Approval period start (RFC3339).")
|
|
64
|
+
.option("--period <period>", "Approval period: WEEKLY, SEMI_MONTHLY, or MONTHLY.")
|
|
65
|
+
.action(async function (opts) {
|
|
66
|
+
const type = requireEnum(opts.type, OTHER_TYPES, "type");
|
|
67
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
68
|
+
const body = {
|
|
69
|
+
periodStart: opts.periodStart,
|
|
70
|
+
};
|
|
71
|
+
if (opts.period)
|
|
72
|
+
body.period = requireEnum(opts.period, PERIODS, "period");
|
|
73
|
+
const created = await client.approvals.submitForUserWithType({
|
|
74
|
+
workspaceId,
|
|
75
|
+
userId: opts.user,
|
|
76
|
+
type,
|
|
77
|
+
body,
|
|
78
|
+
});
|
|
79
|
+
const data = approvalReceiptData(created);
|
|
80
|
+
printReceipt({
|
|
81
|
+
ok: true,
|
|
82
|
+
action: "approvals.submit-for-user-with-type",
|
|
83
|
+
entity: "approval_request",
|
|
84
|
+
ids: { approvalRequestId: data.id, userId: opts.user },
|
|
85
|
+
data,
|
|
86
|
+
changed: { created: [{ type: "approval_request", id: data.id }] },
|
|
87
|
+
next: [
|
|
88
|
+
{
|
|
89
|
+
command: "clk115 api GET /workspaces/{workspaceId}/approval-requests --json",
|
|
90
|
+
reason: "Review the submitted request.",
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
}, output);
|
|
94
|
+
});
|
|
95
|
+
};
|
|
@@ -1,38 +1,42 @@
|
|
|
1
1
|
import { AUDIT_LOG_ACTIONS, } from "clockify-sdk-ts-115/requests";
|
|
2
2
|
import { printRecords } from "../output.js";
|
|
3
|
-
import { clampPageSize, parseIntArg, resolveContext, splitList } from "./helpers.js";
|
|
3
|
+
import { clampPageSize, parseIntArg, promoteDateBoundary, resolveContext, splitList, } from "./helpers.js";
|
|
4
4
|
import { leafCommand } from "./leaf-command.js";
|
|
5
5
|
export const registerAuditLogCommand = (program, services) => {
|
|
6
6
|
const audit = program.command("audit-log").description("Workspace audit log.");
|
|
7
7
|
leafCommand(audit, "search", "read")
|
|
8
8
|
.description("Search the workspace audit log.")
|
|
9
|
-
.requiredOption("--start <date>", "Window start (RFC3339, e.g. 2026-05-01T00:00:00Z).")
|
|
10
|
-
.requiredOption("--end <date>", "Window end (RFC3339).")
|
|
9
|
+
.requiredOption("--start <date>", "Window start (YYYY-MM-DD or RFC3339, e.g. 2026-05-01T00:00:00Z).")
|
|
10
|
+
.requiredOption("--end <date>", "Window end (YYYY-MM-DD or RFC3339); the server caps the window at 31 days.")
|
|
11
11
|
.requiredOption("--actions <list>", "Comma-separated action names (e.g. CREATE_PROJECT,UPDATE_PROJECT).")
|
|
12
12
|
.option("--authors <ids>", "Comma-separated author IDs to include. Pass SYSTEM to include system audit events.")
|
|
13
13
|
.option("--authors-mode <mode>", "Author filter mode (CONTAINS|DOES_NOT_CONTAIN). Defaults to CONTAINS when authors are provided.", "CONTAINS")
|
|
14
14
|
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
15
|
-
.option("--limit <n>", "Items per page (default 50, max
|
|
15
|
+
.option("--limit <n>", "Items per page (default 50, max 50 — the audit-log server caps page size).", parseIntArg, 50)
|
|
16
16
|
.action(async function (opts) {
|
|
17
17
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
18
|
-
const actions = splitList(opts.actions);
|
|
18
|
+
const actions = splitList(opts.actions).map((action) => action.toUpperCase());
|
|
19
19
|
if (actions.length === 0) {
|
|
20
20
|
throw new Error("--actions must include at least one action name");
|
|
21
21
|
}
|
|
22
22
|
const knownActions = new Set(AUDIT_LOG_ACTIONS);
|
|
23
23
|
const invalidActions = actions.filter((action) => !knownActions.has(action));
|
|
24
24
|
if (invalidActions.length > 0) {
|
|
25
|
-
throw new Error(`Unknown audit action(s): ${invalidActions.join(", ")}`);
|
|
25
|
+
throw new Error(`Unknown audit action(s): ${invalidActions.join(", ")}; provide known audit action names such as CREATE_PROJECT or UPDATE_PROJECT`);
|
|
26
26
|
}
|
|
27
27
|
const authorIds = opts.authors ? splitList(opts.authors) : [];
|
|
28
|
+
const mode = String(opts.authorsMode).toUpperCase();
|
|
29
|
+
if (mode !== "CONTAINS" && mode !== "DOES_NOT_CONTAIN") {
|
|
30
|
+
throw new Error(`--authors-mode must be CONTAINS or DOES_NOT_CONTAIN (got "${String(opts.authorsMode)}").`);
|
|
31
|
+
}
|
|
28
32
|
const authors = {
|
|
29
33
|
authorIds,
|
|
30
|
-
contains:
|
|
34
|
+
contains: mode,
|
|
31
35
|
};
|
|
32
36
|
const req = {
|
|
33
37
|
workspaceId,
|
|
34
|
-
start: opts.start,
|
|
35
|
-
end: opts.end,
|
|
38
|
+
start: promoteDateBoundary(opts.start, "start", "start"),
|
|
39
|
+
end: promoteDateBoundary(opts.end, "end", "end"),
|
|
36
40
|
actions: actions,
|
|
37
41
|
authors,
|
|
38
42
|
page: opts.page,
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { printRecords } from "../output.js";
|
|
2
|
+
import { printReceipt } from "../receipt.js";
|
|
3
|
+
import { parseSignedFloatArg, resolveContext, splitList } from "./helpers.js";
|
|
4
|
+
import { leafCommand } from "./leaf-command.js";
|
|
5
|
+
function dateRange(opts) {
|
|
6
|
+
if (opts.start === undefined && opts.end === undefined)
|
|
7
|
+
return undefined;
|
|
8
|
+
const range = {};
|
|
9
|
+
if (opts.start !== undefined)
|
|
10
|
+
range.start = opts.start;
|
|
11
|
+
if (opts.end !== undefined)
|
|
12
|
+
range.end = opts.end;
|
|
13
|
+
return range;
|
|
14
|
+
}
|
|
15
|
+
export function registerBalanceAssignmentCommands(timeoff, services) {
|
|
16
|
+
const group = timeoff
|
|
17
|
+
.command("balance-assignment")
|
|
18
|
+
.description("Per-user, per-policy time-off balance assignments.");
|
|
19
|
+
leafCommand(group, "list", "read")
|
|
20
|
+
.description("List a user's balance assignments for one policy.")
|
|
21
|
+
.requiredOption("--user <id>", "User ID.")
|
|
22
|
+
.requiredOption("--policy <id>", "Time-off policy ID.")
|
|
23
|
+
.action(async function (opts) {
|
|
24
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
25
|
+
const assignments = await client.balanceAssignment.getBalanceAssignmentsForUserAndPolicy({
|
|
26
|
+
workspaceId,
|
|
27
|
+
userId: opts.user,
|
|
28
|
+
policyId: opts.policy,
|
|
29
|
+
});
|
|
30
|
+
const rows = assignments.map((assignment) => ({
|
|
31
|
+
id: assignment.id ?? "",
|
|
32
|
+
user: assignment.userId ?? "",
|
|
33
|
+
policy: assignment.policyId ?? "",
|
|
34
|
+
balance: assignment.balance ?? 0,
|
|
35
|
+
accrued: assignment.accrued ?? 0,
|
|
36
|
+
}));
|
|
37
|
+
printRecords(rows, output);
|
|
38
|
+
});
|
|
39
|
+
leafCommand(group, "create", "write")
|
|
40
|
+
.description("Add balance for one or more users on a policy. Adds to an existing assignment; creates one when absent.")
|
|
41
|
+
.requiredOption("--policy <id>", "Time-off policy ID.")
|
|
42
|
+
.requiredOption("--user <ids>", "Comma-separated user IDs.")
|
|
43
|
+
.requiredOption("--balance <amount>", "Balance to add (may be negative).", parseSignedFloatArg)
|
|
44
|
+
.option("--note <text>", "Note explaining the balance change.")
|
|
45
|
+
.option("--start <date>", "Balance window start (YYYY-MM-DD).")
|
|
46
|
+
.option("--end <date>", "Balance window end (YYYY-MM-DD).")
|
|
47
|
+
.action(async function (opts) {
|
|
48
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
49
|
+
const userIds = splitList(opts.user);
|
|
50
|
+
if (userIds.length === 0)
|
|
51
|
+
throw new Error("--user needs at least one user ID");
|
|
52
|
+
const body = {
|
|
53
|
+
balance: opts.balance,
|
|
54
|
+
policyId: opts.policy,
|
|
55
|
+
userIds,
|
|
56
|
+
};
|
|
57
|
+
if (opts.note !== undefined)
|
|
58
|
+
body.note = opts.note;
|
|
59
|
+
const range = dateRange(opts);
|
|
60
|
+
if (range !== undefined)
|
|
61
|
+
body.dateRange = range;
|
|
62
|
+
await client.balanceAssignment.createBalanceAssignment({ workspaceId, body });
|
|
63
|
+
printReceipt({
|
|
64
|
+
ok: true,
|
|
65
|
+
action: "timeoff.balance-assignment.create",
|
|
66
|
+
entity: "balance_assignment",
|
|
67
|
+
ids: { policyId: opts.policy },
|
|
68
|
+
data: { policyId: opts.policy, userIds, balance: opts.balance },
|
|
69
|
+
warnings: [
|
|
70
|
+
"The API returns no assignment ID. Run the listed read-back to see the resulting balance.",
|
|
71
|
+
],
|
|
72
|
+
next: [
|
|
73
|
+
{
|
|
74
|
+
command: `clk115 timeoff balance-assignment list --user ${userIds[0]} --policy ${opts.policy} --json`,
|
|
75
|
+
reason: "Read back the resulting balance.",
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
}, output);
|
|
79
|
+
});
|
|
80
|
+
leafCommand(group, "update", "write")
|
|
81
|
+
.description("Apply a balance delta to one assignment. The change adds to the current balance.")
|
|
82
|
+
.requiredOption("--id <id>", "Balance assignment ID.")
|
|
83
|
+
.requiredOption("--user <id>", "User ID.")
|
|
84
|
+
.requiredOption("--policy <id>", "Time-off policy ID.")
|
|
85
|
+
.requiredOption("--change <amount>", "Balance delta; negative withdraws balance.", parseSignedFloatArg)
|
|
86
|
+
.option("--note <text>", "Note explaining the balance change.")
|
|
87
|
+
.option("--start <date>", "Balance window start (YYYY-MM-DD).")
|
|
88
|
+
.option("--end <date>", "Balance window end (YYYY-MM-DD).")
|
|
89
|
+
.action(async function (opts) {
|
|
90
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
91
|
+
const body = { balanceChange: opts.change };
|
|
92
|
+
if (opts.note !== undefined)
|
|
93
|
+
body.note = opts.note;
|
|
94
|
+
const range = dateRange(opts);
|
|
95
|
+
if (range !== undefined)
|
|
96
|
+
body.dateRange = range;
|
|
97
|
+
await client.balanceAssignment.updateBalanceAssignment({
|
|
98
|
+
workspaceId,
|
|
99
|
+
userId: opts.user,
|
|
100
|
+
policyId: opts.policy,
|
|
101
|
+
balanceAssignmentId: opts.id,
|
|
102
|
+
body,
|
|
103
|
+
});
|
|
104
|
+
printReceipt({
|
|
105
|
+
ok: true,
|
|
106
|
+
action: "timeoff.balance-assignment.update",
|
|
107
|
+
entity: "balance_assignment",
|
|
108
|
+
ids: { balanceAssignmentId: opts.id, userId: opts.user, policyId: opts.policy },
|
|
109
|
+
data: { id: opts.id, balanceChange: opts.change },
|
|
110
|
+
changed: { updated: [{ type: "balance_assignment", id: opts.id }] },
|
|
111
|
+
next: [
|
|
112
|
+
{
|
|
113
|
+
command: `clk115 timeoff balance-assignment list --user ${opts.user} --policy ${opts.policy} --json`,
|
|
114
|
+
reason: "Read back the resulting balance.",
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
}, output);
|
|
118
|
+
});
|
|
119
|
+
leafCommand(group, "delete", "destructive")
|
|
120
|
+
.description("Delete a balance assignment. The API requires a note.")
|
|
121
|
+
.requiredOption("--id <id>", "Balance assignment ID.")
|
|
122
|
+
.requiredOption("--user <id>", "User ID.")
|
|
123
|
+
.requiredOption("--policy <id>", "Time-off policy ID.")
|
|
124
|
+
.requiredOption("--note <text>", "Note explaining the deletion. The API rejects an empty note.")
|
|
125
|
+
.action(async function (opts) {
|
|
126
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
127
|
+
await client.balanceAssignment.deleteBalanceAssignment({
|
|
128
|
+
workspaceId,
|
|
129
|
+
userId: opts.user,
|
|
130
|
+
policyId: opts.policy,
|
|
131
|
+
balanceAssignmentId: opts.id,
|
|
132
|
+
body: { note: opts.note },
|
|
133
|
+
});
|
|
134
|
+
printReceipt({
|
|
135
|
+
ok: true,
|
|
136
|
+
action: "timeoff.balance-assignment.delete",
|
|
137
|
+
entity: "balance_assignment",
|
|
138
|
+
ids: { balanceAssignmentId: opts.id, userId: opts.user, policyId: opts.policy },
|
|
139
|
+
data: { id: opts.id, deleted: true, message: `deleted balance assignment ${opts.id}` },
|
|
140
|
+
changed: { deleted: [{ type: "balance_assignment", id: opts.id }] },
|
|
141
|
+
next: [
|
|
142
|
+
{
|
|
143
|
+
command: `clk115 timeoff balance-assignment list --user ${opts.user} --policy ${opts.policy} --json`,
|
|
144
|
+
reason: "Verify the assignment no longer appears.",
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
}, output);
|
|
148
|
+
});
|
|
149
|
+
}
|
package/dist/commands/clients.js
CHANGED
|
@@ -130,7 +130,7 @@ export const registerClientsCommand = (program, services) => {
|
|
|
130
130
|
opts.address !== undefined ||
|
|
131
131
|
opts.archived !== undefined;
|
|
132
132
|
if (!hasChanges) {
|
|
133
|
-
throw new Error("clients.update
|
|
133
|
+
throw new Error("clients.update needs a change: provide at least one client field.");
|
|
134
134
|
}
|
|
135
135
|
const current = (await client.clients.get({
|
|
136
136
|
workspaceId,
|
|
@@ -151,7 +151,7 @@ export const registerClientsCommand = (program, services) => {
|
|
|
151
151
|
body.archived = opts.archived;
|
|
152
152
|
}
|
|
153
153
|
if (!changed) {
|
|
154
|
-
throw new Error("clients.update values are unchanged;
|
|
154
|
+
throw new Error("clients.update values are unchanged; provide a different value.");
|
|
155
155
|
}
|
|
156
156
|
const req = {
|
|
157
157
|
workspaceId,
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { classifyClockifyBaseUrl } from "clockify-sdk-ts-115/create-client";
|
|
2
2
|
import { buildRoutingOptions } from "../client.js";
|
|
3
3
|
import { globalFlags, resolveFlags } from "../index.js";
|
|
4
|
-
import { printObject } from "../output.js";
|
|
4
|
+
import { printObject, printRecords } from "../output.js";
|
|
5
5
|
import { rootProgram } from "./helpers.js";
|
|
6
6
|
import { leafCommand } from "./leaf-command.js";
|
|
7
7
|
const DEFAULT_CLOCKIFY_BASE_URL = "https://api.clockify.me/api/v1";
|
|
@@ -13,12 +13,29 @@ export const registerDoctorCommand = (program, services) => {
|
|
|
13
13
|
const flags = globalFlags(root);
|
|
14
14
|
const config = services.loadConfig(flags);
|
|
15
15
|
const output = resolveFlags(root);
|
|
16
|
-
|
|
16
|
+
const receipt = buildDoctorReceipt(config, flags, process.env);
|
|
17
|
+
if (output.mode !== "table") {
|
|
18
|
+
printObject(receipt, output);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
printRecords(Object.entries(receipt.checks).map(([check, c]) => ({
|
|
22
|
+
check,
|
|
23
|
+
ok: c.ok,
|
|
24
|
+
status: c.status,
|
|
25
|
+
source: c.source ?? "",
|
|
26
|
+
value: c.value ?? "",
|
|
27
|
+
recovery: c.recovery ?? "",
|
|
28
|
+
})), output);
|
|
29
|
+
printObject({ ok: receipt.ok, readiness: receipt.readiness }, output);
|
|
30
|
+
for (const step of receipt.next)
|
|
31
|
+
console.log(step);
|
|
17
32
|
});
|
|
18
33
|
};
|
|
19
34
|
function buildDoctorReceipt(config, flags, env) {
|
|
20
|
-
const nodeMajor =
|
|
21
|
-
|
|
35
|
+
const [nodeMajor = 0, nodeMinor = 0] = process.versions.node
|
|
36
|
+
.split(".")
|
|
37
|
+
.map((part) => Number.parseInt(part, 10) || 0);
|
|
38
|
+
const nodeOk = nodeMajor > 22 || (nodeMajor === 22 && nodeMinor >= 13);
|
|
22
39
|
const apiKeySource = sourceFor("apiKey", config, flags, env);
|
|
23
40
|
const workspaceSource = sourceFor("workspaceId", config, flags, env);
|
|
24
41
|
const baseUrlSource = sourceFor("baseUrl", config, flags, env) ?? "default";
|