@apet97/clockify-cli-115 0.5.0 → 0.6.1
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 +12 -5
- package/dist/commands/approvals.js +95 -0
- package/dist/commands/balanceAssignment.js +149 -0
- package/dist/commands/entries.js +26 -1
- package/dist/commands/helpers.js +7 -0
- package/dist/commands/projects.js +10 -1
- package/dist/commands/reports.js +17 -2
- package/dist/commands/sharedReports.js +12 -15
- package/dist/commands/timeoff.js +4 -1
- package/dist/commands/webhooks.js +3 -3
- package/dist/completions.js +1 -0
- package/dist/generated/version.js +1 -1
- package/dist/index.js +19 -4
- package/package.json +2 -2
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.1`. Requires Node.js `>=22.13.0` and
|
|
7
|
+
`clockify-sdk-ts-115 >=0.15.1 <1`.
|
|
8
8
|
|
|
9
9
|
Two binaries, identical behavior:
|
|
10
10
|
|
|
@@ -92,6 +92,7 @@ Legacy top-level fields such as `id` remain for simple shell scripts.
|
|
|
92
92
|
| `clk115 stop` | Stop the running timer for the current user. |
|
|
93
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`. |
|
|
94
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. |
|
|
95
96
|
| `clk115 entries delete <id>` | Delete a time entry. |
|
|
96
97
|
| `clk115 projects list [--limit N] [--page N] [--name text] [--archived] [--client id]` | List projects. |
|
|
97
98
|
| `clk115 projects create <name> [--client id] [--color hex] [--billable]` | Create a project. |
|
|
@@ -125,15 +126,19 @@ Legacy top-level fields such as `id` remain for simple shell scripts.
|
|
|
125
126
|
| `clk115 expenses delete <id>` | Delete an expense. |
|
|
126
127
|
| `clk115 timeoff list [--page N] [--limit N] [--start date] [--end date] [--status APPROVED,PENDING,…] [--user ids]` | List time-off requests. |
|
|
127
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). |
|
|
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. |
|
|
128
133
|
| `clk115 scheduling list --from date --to date [--limit N] [--page N] [--name text]` | List scheduling assignments. |
|
|
129
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. |
|
|
130
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. |
|
|
131
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. |
|
|
132
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. |
|
|
133
|
-
| `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. |
|
|
134
139
|
| `clk115 reports attendance [--period p] [--from date] [--to date]` | Attendance report of clock-in/out activity over a date range. Read-only. |
|
|
135
140
|
| `clk115 shared-reports list` | List the workspace's shared (public-link) reports. Read-only. |
|
|
136
|
-
| `clk115 shared-reports view <id> [--export-type JSON_V1\|JSON\|CSV
|
|
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. |
|
|
137
142
|
| `clk115 shared-reports create --name X --type T --filter json [--public\|--no-public]` | Create a shared (public-link) report. |
|
|
138
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). |
|
|
139
144
|
| `clk115 shared-reports delete <id>` | Delete a shared report. |
|
|
@@ -142,6 +147,8 @@ Legacy top-level fields such as `id` remain for simple shell scripts.
|
|
|
142
147
|
| `clk115 users invite <email> [--no-send-email]` | Invite (add) a user to the workspace by email. |
|
|
143
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. |
|
|
144
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. |
|
|
145
152
|
| `clk115 completion [zsh\|bash\|fish]` | Print a shell completion script for zsh, bash, or fish. |
|
|
146
153
|
| `clk115 help [command]` | Print per-command help. |
|
|
147
154
|
| `clk115 --version` | Print CLI version. |
|
|
@@ -232,7 +239,7 @@ node dist/index.js status # smoke test (or invoke installed clk115/clockify11
|
|
|
232
239
|
```
|
|
233
240
|
|
|
234
241
|
`clockify-sdk-ts-115` is workspace-linked for local development and is a
|
|
235
|
-
`>=0.
|
|
242
|
+
`>=0.15.1 <1` peer dependency for published consumers.
|
|
236
243
|
|
|
237
244
|
## License
|
|
238
245
|
|
|
@@ -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
|
+
};
|
|
@@ -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/entries.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { entityId } from "clockify-sdk-ts-115/operation-receipt";
|
|
2
2
|
import { printRecords } from "../output.js";
|
|
3
3
|
import { printReceipt } from "../receipt.js";
|
|
4
|
-
import { clampPageSize, parseIntArg, promoteDateBoundary, resolveContext } from "./helpers.js";
|
|
4
|
+
import { clampPageSize, parseIntArg, promoteDateBoundary, resolveContext, splitList, } from "./helpers.js";
|
|
5
5
|
import { leafCommand } from "./leaf-command.js";
|
|
6
6
|
export const registerEntriesCommand = (program, services) => {
|
|
7
7
|
const entries = program.command("entries").description("Manage time entries.");
|
|
@@ -47,6 +47,31 @@ export const registerEntriesCommand = (program, services) => {
|
|
|
47
47
|
});
|
|
48
48
|
printRecords(rows, output);
|
|
49
49
|
});
|
|
50
|
+
leafCommand(entries, "get-many", "read")
|
|
51
|
+
.description("Look up several time entries by ID in one call.")
|
|
52
|
+
.requiredOption("--ids <ids>", "Comma-separated time-entry IDs.")
|
|
53
|
+
.option("--hydrated", "Include project, task, and tag detail.", false)
|
|
54
|
+
.action(async function (opts) {
|
|
55
|
+
const timeEntryIds = splitList(opts.ids);
|
|
56
|
+
if (timeEntryIds.length === 0)
|
|
57
|
+
throw new Error("--ids needs at least one time-entry ID");
|
|
58
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
59
|
+
const items = await client.timeEntries.getMultipleTimeEntries({
|
|
60
|
+
workspaceId,
|
|
61
|
+
body: { timeEntryIds, hydrated: opts.hydrated === true },
|
|
62
|
+
});
|
|
63
|
+
const rows = items.map((entry) => ({
|
|
64
|
+
id: entry.id ?? "",
|
|
65
|
+
description: entry.description ?? "",
|
|
66
|
+
project: entry.projectId ?? "",
|
|
67
|
+
task: entry.taskId ?? "",
|
|
68
|
+
billable: entry.billable === true,
|
|
69
|
+
start: entry.timeInterval?.start ?? "",
|
|
70
|
+
end: entry.timeInterval?.end ?? "",
|
|
71
|
+
duration: entry.timeInterval?.duration ?? "",
|
|
72
|
+
}));
|
|
73
|
+
printRecords(rows, output);
|
|
74
|
+
});
|
|
50
75
|
leafCommand(entries, "delete", "destructive")
|
|
51
76
|
.argument("<id>", "Time-entry ID.")
|
|
52
77
|
.description("Delete a time entry by ID.")
|
package/dist/commands/helpers.js
CHANGED
|
@@ -15,6 +15,13 @@ export function parseFloatArg(value) {
|
|
|
15
15
|
}
|
|
16
16
|
return parsed;
|
|
17
17
|
}
|
|
18
|
+
export function parseSignedFloatArg(value) {
|
|
19
|
+
const parsed = Number.parseFloat(value);
|
|
20
|
+
if (!Number.isFinite(parsed)) {
|
|
21
|
+
throw new InvalidArgumentError("must be a number.");
|
|
22
|
+
}
|
|
23
|
+
return parsed;
|
|
24
|
+
}
|
|
18
25
|
export function clampPageSize(value, max) {
|
|
19
26
|
return Math.min(value, max);
|
|
20
27
|
}
|
|
@@ -3,6 +3,12 @@ import { printObject, printRecords } from "../output.js";
|
|
|
3
3
|
import { printReceipt } from "../receipt.js";
|
|
4
4
|
import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
|
|
5
5
|
import { leafCommand } from "./leaf-command.js";
|
|
6
|
+
function projectUpdateCarryFields(current) {
|
|
7
|
+
if (typeof current.billable !== "boolean" || typeof current.public !== "boolean") {
|
|
8
|
+
throw new Error("Cannot update project safely: the current project did not return boolean billable and public fields.");
|
|
9
|
+
}
|
|
10
|
+
return { billable: current.billable, isPublic: current.public };
|
|
11
|
+
}
|
|
6
12
|
export const registerProjectsCommand = (program, services) => {
|
|
7
13
|
const projects = program.command("projects").description("Manage projects.");
|
|
8
14
|
leafCommand(projects, "list", "read")
|
|
@@ -108,7 +114,8 @@ export const registerProjectsCommand = (program, services) => {
|
|
|
108
114
|
throw new Error("projects.update needs a change: provide at least one project field.");
|
|
109
115
|
}
|
|
110
116
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
111
|
-
const
|
|
117
|
+
const current = await client.projects.get({ workspaceId, projectId: id });
|
|
118
|
+
const body = projectUpdateCarryFields(current);
|
|
112
119
|
if (opts.name)
|
|
113
120
|
body.name = opts.name;
|
|
114
121
|
if (opts.client)
|
|
@@ -150,10 +157,12 @@ export const registerProjectsCommand = (program, services) => {
|
|
|
150
157
|
adapter: {
|
|
151
158
|
getCurrent: ({ workspaceId: currentWorkspaceId, id: projectId }) => client.projects.get({ workspaceId: currentWorkspaceId, projectId }),
|
|
152
159
|
archive: async ({ workspaceId: currentWorkspaceId, id: projectId, current, }) => {
|
|
160
|
+
const preserved = projectUpdateCarryFields(current);
|
|
153
161
|
await client.projects.update({
|
|
154
162
|
workspaceId: currentWorkspaceId,
|
|
155
163
|
projectId,
|
|
156
164
|
name: current.name,
|
|
165
|
+
...preserved,
|
|
157
166
|
archived: true,
|
|
158
167
|
});
|
|
159
168
|
},
|
package/dist/commands/reports.js
CHANGED
|
@@ -29,6 +29,19 @@ function resolveRange(opts) {
|
|
|
29
29
|
}
|
|
30
30
|
return { dateRangeStart, dateRangeEnd };
|
|
31
31
|
}
|
|
32
|
+
function assertWeeklyRange(dateRangeStart, dateRangeEnd) {
|
|
33
|
+
const start = new Date(dateRangeStart);
|
|
34
|
+
const end = new Date(dateRangeEnd);
|
|
35
|
+
if (Number.isNaN(start.getTime()) || Number.isNaN(end.getTime())) {
|
|
36
|
+
throw new Error("Weekly reports require valid dateRangeStart and dateRangeEnd values.");
|
|
37
|
+
}
|
|
38
|
+
const elapsedMs = end.getTime() - start.getTime();
|
|
39
|
+
const exclusiveWeekMs = 7 * 86_400_000;
|
|
40
|
+
const inclusiveWeekMs = exclusiveWeekMs - 1;
|
|
41
|
+
if (elapsedMs !== exclusiveWeekMs && elapsedMs !== inclusiveWeekMs) {
|
|
42
|
+
throw new Error("Weekly reports require one exact seven-day interval (exclusive end) or its inclusive end-of-day equivalent. Provide --from and --to for one Monday-Sunday window or use --period last_week.");
|
|
43
|
+
}
|
|
44
|
+
}
|
|
32
45
|
function idFilter(ids) {
|
|
33
46
|
return { ids, contains: "CONTAINS" };
|
|
34
47
|
}
|
|
@@ -41,6 +54,7 @@ const SUMMARY_GROUPS = [
|
|
|
41
54
|
"MONTH",
|
|
42
55
|
"TIMEENTRY",
|
|
43
56
|
"TASK",
|
|
57
|
+
"TAG",
|
|
44
58
|
];
|
|
45
59
|
function parseSummaryGroups(raw) {
|
|
46
60
|
const groups = String(raw)
|
|
@@ -128,8 +142,8 @@ export const registerReportsCommand = (program, services) => {
|
|
|
128
142
|
printObject(data, output);
|
|
129
143
|
});
|
|
130
144
|
leafCommand(reports, "weekly", "read")
|
|
131
|
-
.description("Weekly report
|
|
132
|
-
.option("--period <p>",
|
|
145
|
+
.description("Weekly report for one exact seven-day interval.")
|
|
146
|
+
.option("--period <p>", "Named period (default last_week).", "last_week")
|
|
133
147
|
.option("--from <date>", "Range start; overrides --period.")
|
|
134
148
|
.option("--to <date>", "Range end; overrides --period.")
|
|
135
149
|
.option("--group <group>", "Top grouping: USER or PROJECT.", "USER")
|
|
@@ -137,6 +151,7 @@ export const registerReportsCommand = (program, services) => {
|
|
|
137
151
|
.action(async function (opts) {
|
|
138
152
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
139
153
|
const { dateRangeStart, dateRangeEnd } = resolveRange(opts);
|
|
154
|
+
assertWeeklyRange(dateRangeStart, dateRangeEnd);
|
|
140
155
|
const req = {
|
|
141
156
|
workspaceId,
|
|
142
157
|
dateRangeStart,
|
|
@@ -3,15 +3,8 @@ import { printObject, printRecords } from "../output.js";
|
|
|
3
3
|
import { printReceipt } from "../receipt.js";
|
|
4
4
|
import { resolveBaseContext, resolveContext } from "./helpers.js";
|
|
5
5
|
import { leafCommand } from "./leaf-command.js";
|
|
6
|
-
async function readReportBody(response
|
|
6
|
+
async function readReportBody(response) {
|
|
7
7
|
const buffer = await response.arrayBuffer();
|
|
8
|
-
if (exportType === "XLSX" || exportType === "PDF") {
|
|
9
|
-
return {
|
|
10
|
-
exportType,
|
|
11
|
-
bytes: buffer.byteLength,
|
|
12
|
-
note: "Binary export; the CLI cannot emit it on stdout without corrupting it. Run `clk115 shared-reports list` and open the report's `link` to download the file.",
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
8
|
const text = new TextDecoder().decode(buffer);
|
|
16
9
|
if (!text)
|
|
17
10
|
return { body: "" };
|
|
@@ -47,7 +40,8 @@ const SHARED_REPORT_TYPES = [
|
|
|
47
40
|
"TIMEOFF_BALANCE",
|
|
48
41
|
"EXPENSE_SUMMARY",
|
|
49
42
|
];
|
|
50
|
-
const
|
|
43
|
+
const SHARED_REPORT_FILTER_EXPORT_TYPES = ["JSON_V1", "JSON", "CSV", "XLSX", "PDF"];
|
|
44
|
+
const SHARED_REPORT_VIEW_EXPORT_TYPES = ["JSON_V1", "JSON", "CSV"];
|
|
51
45
|
const SUMMARY_GROUPS = [
|
|
52
46
|
"CLIENT",
|
|
53
47
|
"PROJECT",
|
|
@@ -65,7 +59,7 @@ const nonEmptyStringSchema = z
|
|
|
65
59
|
const dateStringSchema = nonEmptyStringSchema.refine((value) => !Number.isNaN(Date.parse(value)), "must be a valid date string.");
|
|
66
60
|
const upperCaseString = (value) => typeof value === "string" ? value.toUpperCase() : value;
|
|
67
61
|
const sharedReportTypeSchema = z.preprocess(upperCaseString, z.enum(SHARED_REPORT_TYPES));
|
|
68
|
-
const sharedReportExportTypeSchema = z.preprocess(upperCaseString, z.enum(
|
|
62
|
+
const sharedReportExportTypeSchema = z.preprocess(upperCaseString, z.enum(SHARED_REPORT_FILTER_EXPORT_TYPES));
|
|
69
63
|
const openObjectSchema = z.record(z.string(), z.unknown());
|
|
70
64
|
const INT_MESSAGE = { error: "provide a whole integer" };
|
|
71
65
|
const sharedUsersFilterSchema = z
|
|
@@ -274,20 +268,23 @@ export const registerSharedReportsCommand = (program, services) => {
|
|
|
274
268
|
});
|
|
275
269
|
leafCommand(shared, "view", "read")
|
|
276
270
|
.argument("<id>", "Shared-report ID.")
|
|
277
|
-
.option("--export-type <type>", "
|
|
271
|
+
.option("--export-type <type>", "Text-safe export type: JSON_V1, JSON, or CSV (default JSON_V1).")
|
|
278
272
|
.description("View a shared report's rendered data by ID (reports host; not workspace-scoped).")
|
|
279
273
|
.action(async function (id, opts) {
|
|
280
|
-
const { client, output } = await resolveBaseContext(this, services);
|
|
281
274
|
const candidate = opts.exportType ? String(opts.exportType).toUpperCase() : "JSON_V1";
|
|
282
|
-
if (
|
|
283
|
-
throw new Error(
|
|
275
|
+
if (candidate === "XLSX" || candidate === "PDF") {
|
|
276
|
+
throw new Error(`--export-type ${candidate} is unavailable because the CLI cannot stream binary output to a file yet. Provide one of: ${SHARED_REPORT_VIEW_EXPORT_TYPES.join(", ")}. Run \`clk115 shared-reports list\` and open the report link for binary downloads.`);
|
|
277
|
+
}
|
|
278
|
+
if (!SHARED_REPORT_VIEW_EXPORT_TYPES.includes(candidate)) {
|
|
279
|
+
throw new Error(`Unknown --export-type "${String(opts.exportType)}". Provide one of: ${SHARED_REPORT_VIEW_EXPORT_TYPES.join(", ")}.`);
|
|
284
280
|
}
|
|
281
|
+
const { client, output } = await resolveBaseContext(this, services);
|
|
285
282
|
const exportType = candidate;
|
|
286
283
|
const response = await client.sharedReports.view({
|
|
287
284
|
sharedReportId: id,
|
|
288
285
|
exportType,
|
|
289
286
|
});
|
|
290
|
-
printObject(await readReportBody(response
|
|
287
|
+
printObject(await readReportBody(response), output);
|
|
291
288
|
});
|
|
292
289
|
leafCommand(shared, "create", "write")
|
|
293
290
|
.requiredOption("--name <text>", "Shared-report name.")
|
package/dist/commands/timeoff.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { printRecords } from "../output.js";
|
|
2
2
|
import { printReceipt } from "../receipt.js";
|
|
3
|
+
import { registerBalanceAssignmentCommands } from "./balanceAssignment.js";
|
|
3
4
|
import { clampPageSize, parseIntArg, resolveContext, splitList } from "./helpers.js";
|
|
4
5
|
import { leafCommand } from "./leaf-command.js";
|
|
5
6
|
export const registerTimeOffCommand = (program, services) => {
|
|
6
7
|
const timeoff = program.command("timeoff").description("Time-off requests.");
|
|
8
|
+
registerBalanceAssignmentCommands(timeoff, services);
|
|
7
9
|
leafCommand(timeoff, "list", "read")
|
|
8
10
|
.description("List time-off requests in the workspace.")
|
|
9
11
|
.option("--page <n>", "Page number.", parseIntArg, 1)
|
|
@@ -33,7 +35,8 @@ export const registerTimeOffCommand = (program, services) => {
|
|
|
33
35
|
}
|
|
34
36
|
if (opts.user)
|
|
35
37
|
req.users = splitList(opts.user);
|
|
36
|
-
const
|
|
38
|
+
const response = await client.timeOff.list(req);
|
|
39
|
+
const items = response.requests ?? [];
|
|
37
40
|
const rows = items.map((raw) => {
|
|
38
41
|
const r = raw;
|
|
39
42
|
const statusValue = typeof r.status === "object" && r.status !== null
|
|
@@ -4,7 +4,7 @@ import { printRecords } from "../output.js";
|
|
|
4
4
|
import { printReceipt } from "../receipt.js";
|
|
5
5
|
import { resolveContext, splitList } from "./helpers.js";
|
|
6
6
|
import { leafCommand } from "./leaf-command.js";
|
|
7
|
-
const WEBHOOK_LIST_TYPES = ["
|
|
7
|
+
const WEBHOOK_LIST_TYPES = ["USER_CREATED", "SYSTEM", "ADDON"];
|
|
8
8
|
const WEBHOOK_TRIGGER_SOURCE_TYPES = [
|
|
9
9
|
"PROJECT_ID",
|
|
10
10
|
"USER_ID",
|
|
@@ -101,14 +101,14 @@ export const registerWebhooksCommand = (program, services) => {
|
|
|
101
101
|
const webhooks = program.command("webhooks").description("Manage outbound webhooks.");
|
|
102
102
|
leafCommand(webhooks, "list", "read")
|
|
103
103
|
.description("List webhooks in the workspace.")
|
|
104
|
-
.option("--type <type>", "Filter by webhook type (
|
|
104
|
+
.option("--type <type>", "Filter by webhook type (USER_CREATED, SYSTEM, ADDON).")
|
|
105
105
|
.action(async function (opts) {
|
|
106
106
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
107
107
|
let type;
|
|
108
108
|
if (opts.type) {
|
|
109
109
|
const candidate = String(opts.type).toUpperCase();
|
|
110
110
|
if (!WEBHOOK_LIST_TYPES.includes(candidate)) {
|
|
111
|
-
throw new Error(`Unknown webhook type: ${opts.type}. Provide one of:
|
|
111
|
+
throw new Error(`Unknown webhook type: ${opts.type}. Provide one of: ${WEBHOOK_LIST_TYPES.join(", ")}.`);
|
|
112
112
|
}
|
|
113
113
|
type = candidate;
|
|
114
114
|
}
|
package/dist/completions.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PACKAGE_VERSION = "0.
|
|
1
|
+
export const PACKAGE_VERSION = "0.6.1";
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { realpathSync } from "node:fs";
|
|
3
|
+
import { pathToFileURL } from "node:url";
|
|
2
4
|
import { Command, InvalidArgumentError } from "commander";
|
|
3
5
|
import { buildClient } from "./client.js";
|
|
4
6
|
import { registerApiCommand } from "./commands/api.js";
|
|
7
|
+
import { registerApprovalsCommand } from "./commands/approvals.js";
|
|
5
8
|
import { registerAuditLogCommand } from "./commands/auditlog.js";
|
|
6
9
|
import { registerClientsCommand } from "./commands/clients.js";
|
|
7
10
|
import { registerDoctorCommand } from "./commands/doctor.js";
|
|
@@ -66,6 +69,7 @@ export function buildProgram(services = defaultServices) {
|
|
|
66
69
|
registerReportsCommand(program, services);
|
|
67
70
|
registerSharedReportsCommand(program, services);
|
|
68
71
|
registerUsersCommand(program, services);
|
|
72
|
+
registerApprovalsCommand(program, services);
|
|
69
73
|
leafCommand(program, "completion", "read")
|
|
70
74
|
.argument("[shell]", "Shell to generate completion for: zsh, bash, or fish.", "zsh")
|
|
71
75
|
.description("Print shell completion script for zsh, bash, or fish.")
|
|
@@ -170,14 +174,25 @@ function isCommanderUsageError(err) {
|
|
|
170
174
|
typeof err.code === "string" &&
|
|
171
175
|
err.code.startsWith("commander."));
|
|
172
176
|
}
|
|
177
|
+
function isDirectInvocation(argv1) {
|
|
178
|
+
if (argv1 === undefined)
|
|
179
|
+
return false;
|
|
180
|
+
try {
|
|
181
|
+
return pathToFileURL(realpathSync(argv1)).href === import.meta.url;
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
return false;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
173
187
|
const invokedDirectly = typeof process !== "undefined" &&
|
|
174
188
|
Array.isArray(process.argv) &&
|
|
175
|
-
process.argv[1]
|
|
176
|
-
/(?:^|\/)(?:clockify115|clk115|index\.[jt]s)$/.test(process.argv[1]);
|
|
189
|
+
isDirectInvocation(process.argv[1]);
|
|
177
190
|
if (invokedDirectly) {
|
|
178
|
-
main(process.argv).then((code) =>
|
|
191
|
+
main(process.argv).then((code) => {
|
|
192
|
+
process.exitCode = code;
|
|
193
|
+
}, (err) => {
|
|
179
194
|
const message = err instanceof Error ? err.message : String(err);
|
|
180
195
|
console.error(`fatal: ${message}`);
|
|
181
|
-
process.
|
|
196
|
+
process.exitCode = 1;
|
|
182
197
|
});
|
|
183
198
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apet97/clockify-cli-115",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "Unofficial, community-built — not affiliated with CAKE.com or Clockify. Command-line interface for Clockify, built on clockify-sdk-ts-115.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Aleksandar Petković <petkovic.aleksandar037@gmail.com>",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"zod": "^4.4.3"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"clockify-sdk-ts-115": ">=0.
|
|
57
|
+
"clockify-sdk-ts-115": ">=0.15.1 <1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/node": "^22",
|