@apet97/clockify-cli-115 5.0.4 → 7.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 +255 -39
- package/dist/client.js +43 -17
- package/dist/closed-pipe.js +3 -0
- package/dist/commands/api.js +192 -103
- package/dist/commands/approvals.js +9 -10
- package/dist/commands/auditlog.js +11 -8
- package/dist/commands/auth.js +229 -0
- package/dist/commands/balanceAssignment.js +10 -8
- package/dist/commands/batch.js +226 -0
- package/dist/commands/clients.js +27 -72
- package/dist/commands/doctor.js +98 -82
- package/dist/commands/entries.js +29 -14
- package/dist/commands/expenses.js +75 -36
- package/dist/commands/helpers.js +74 -9
- package/dist/commands/invoices.js +12 -16
- package/dist/commands/leaf-command.js +15 -0
- package/dist/commands/log.js +4 -2
- package/dist/commands/manifest.js +63 -0
- package/dist/commands/operations.js +271 -0
- package/dist/commands/projects.js +28 -32
- package/dist/commands/reports.js +54 -21
- package/dist/commands/resolve-refs.js +30 -53
- package/dist/commands/scheduling.js +94 -40
- package/dist/commands/shared-report-body.js +127 -0
- package/dist/commands/sharedReports.js +19 -235
- package/dist/commands/skill.js +85 -0
- package/dist/commands/start.js +6 -4
- package/dist/commands/status.js +69 -27
- package/dist/commands/stop.js +7 -18
- package/dist/commands/tags.js +11 -11
- package/dist/commands/tasks.js +27 -133
- package/dist/commands/timeoff.js +23 -16
- package/dist/commands/users.js +11 -19
- package/dist/commands/webhook-delivery.js +331 -0
- package/dist/commands/webhooks.js +40 -104
- package/dist/completions.js +291 -55
- package/dist/config.js +168 -61
- package/dist/credentials.js +164 -0
- package/dist/duration.js +5 -4
- package/dist/failure.js +82 -0
- package/dist/flags.js +84 -0
- package/dist/generated/version.js +1 -1
- package/dist/index.js +68 -108
- package/dist/interrupts.js +28 -0
- package/dist/output.js +189 -66
- package/dist/receipt.js +2 -10
- package/dist/stdin.js +6 -0
- package/dist/stdout.js +38 -0
- package/dist/write-outcome.js +84 -0
- package/package.json +6 -4
- 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 -272
package/dist/commands/clients.js
CHANGED
|
@@ -1,56 +1,14 @@
|
|
|
1
1
|
import { archiveThenDeleteClient } from "clockify-sdk-ts-115/ensure";
|
|
2
|
+
import { clientUpdate } from "clockify-sdk-ts-115/updates";
|
|
3
|
+
import { PartialDeleteError, UsageError } from "../failure.js";
|
|
2
4
|
import { printObject, printRecords } from "../output.js";
|
|
3
5
|
import { printReceipt } from "../receipt.js";
|
|
6
|
+
import { dispatchedWrite } from "../write-outcome.js";
|
|
4
7
|
import { clampPageSize, parseIntArg, resolveContext } from "./helpers.js";
|
|
5
8
|
import { leafCommand } from "./leaf-command.js";
|
|
6
9
|
function quoteShellArgument(value) {
|
|
7
10
|
return `'${value.replaceAll("'", "'\"'\"'")}'`;
|
|
8
11
|
}
|
|
9
|
-
function requireClientName(value, source) {
|
|
10
|
-
if (typeof value !== "string" || value.trim() === "") {
|
|
11
|
-
throw new Error(`${source} is missing the required client name; refusing to mutate.`);
|
|
12
|
-
}
|
|
13
|
-
return value;
|
|
14
|
-
}
|
|
15
|
-
function optionalClientString(value, field) {
|
|
16
|
-
if (value === undefined)
|
|
17
|
-
return undefined;
|
|
18
|
-
if (typeof value !== "string") {
|
|
19
|
-
throw new Error(`Current client has invalid ${field}; refusing to mutate.`);
|
|
20
|
-
}
|
|
21
|
-
return value;
|
|
22
|
-
}
|
|
23
|
-
function optionalNullableClientString(value, field) {
|
|
24
|
-
if (value === null)
|
|
25
|
-
return undefined;
|
|
26
|
-
return optionalClientString(value, field);
|
|
27
|
-
}
|
|
28
|
-
function requiredClientArchived(value) {
|
|
29
|
-
if (typeof value !== "boolean") {
|
|
30
|
-
throw new Error("Current client has invalid or missing archived state; refusing to mutate.");
|
|
31
|
-
}
|
|
32
|
-
return value;
|
|
33
|
-
}
|
|
34
|
-
function reconstructClientBody(current, suppliedName) {
|
|
35
|
-
const body = {
|
|
36
|
-
name: suppliedName !== undefined
|
|
37
|
-
? requireClientName(suppliedName, "Client update request")
|
|
38
|
-
: requireClientName(current.name, "Current client"),
|
|
39
|
-
};
|
|
40
|
-
const address = optionalNullableClientString(current.address, "address");
|
|
41
|
-
if (address !== undefined)
|
|
42
|
-
body.address = address;
|
|
43
|
-
if (current.ccEmails != null)
|
|
44
|
-
body.ccEmails = current.ccEmails;
|
|
45
|
-
const email = optionalNullableClientString(current.email, "email");
|
|
46
|
-
if (email !== undefined)
|
|
47
|
-
body.email = email;
|
|
48
|
-
const note = optionalNullableClientString(current.note, "note");
|
|
49
|
-
if (note !== undefined)
|
|
50
|
-
body.note = note;
|
|
51
|
-
body.archived = requiredClientArchived(current.archived);
|
|
52
|
-
return body;
|
|
53
|
-
}
|
|
54
12
|
export const registerClientsCommand = (program, services) => {
|
|
55
13
|
const clients = program.command("clients").description("Manage clients.");
|
|
56
14
|
leafCommand(clients, "list", "read")
|
|
@@ -98,7 +56,7 @@ export const registerClientsCommand = (program, services) => {
|
|
|
98
56
|
workspaceId,
|
|
99
57
|
body: { name, ...(opts.note !== undefined ? { note: opts.note } : {}) },
|
|
100
58
|
};
|
|
101
|
-
const created = (await client.clients.create(req));
|
|
59
|
+
const created = (await dispatchedWrite(this, client.clients.create(req)));
|
|
102
60
|
const data = { id: created.id ?? "", name: created.name ?? "" };
|
|
103
61
|
printReceipt({
|
|
104
62
|
ok: true,
|
|
@@ -136,33 +94,23 @@ export const registerClientsCommand = (program, services) => {
|
|
|
136
94
|
" $ clk115 clients update client_123 --name \"New name\"\n" +
|
|
137
95
|
" $ clk115 clients update client_123 --archived\n")
|
|
138
96
|
.action(async function (id, opts) {
|
|
139
|
-
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
140
97
|
const hasChanges = opts.name !== undefined ||
|
|
141
98
|
opts.note !== undefined ||
|
|
142
99
|
opts.address !== undefined ||
|
|
143
100
|
opts.archived !== undefined;
|
|
144
101
|
if (!hasChanges) {
|
|
145
|
-
throw new
|
|
102
|
+
throw new UsageError("clients.update needs a change: provide at least one client field.");
|
|
146
103
|
}
|
|
147
|
-
const
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (opts.address !== undefined) {
|
|
158
|
-
changed = changed || opts.address !== body.address;
|
|
159
|
-
body.address = opts.address;
|
|
160
|
-
}
|
|
161
|
-
if (opts.archived !== undefined) {
|
|
162
|
-
changed = changed || opts.archived !== body.archived;
|
|
163
|
-
body.archived = opts.archived;
|
|
164
|
-
}
|
|
165
|
-
if (!changed) {
|
|
104
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
105
|
+
const patch = {
|
|
106
|
+
name: opts.name,
|
|
107
|
+
note: opts.note,
|
|
108
|
+
address: opts.address,
|
|
109
|
+
archived: opts.archived,
|
|
110
|
+
};
|
|
111
|
+
const current = await client.clients.get({ workspaceId, clientId: id });
|
|
112
|
+
const body = clientUpdate.body(current, patch);
|
|
113
|
+
if (clientUpdate.changed(current, patch).length === 0) {
|
|
166
114
|
throw new Error("clients.update values are unchanged; provide a different value.");
|
|
167
115
|
}
|
|
168
116
|
const req = {
|
|
@@ -170,7 +118,7 @@ export const registerClientsCommand = (program, services) => {
|
|
|
170
118
|
clientId: id,
|
|
171
119
|
body,
|
|
172
120
|
};
|
|
173
|
-
const updated = (await client.clients.update(req));
|
|
121
|
+
const updated = (await dispatchedWrite(this, client.clients.update(req)));
|
|
174
122
|
const data = { id: updated.id ?? id, name: updated.name ?? body.name };
|
|
175
123
|
printReceipt({
|
|
176
124
|
ok: true,
|
|
@@ -193,20 +141,27 @@ export const registerClientsCommand = (program, services) => {
|
|
|
193
141
|
.addHelpText("after", "\nExamples:\n" + " $ clk115 clients delete client_123\n")
|
|
194
142
|
.action(async function (id) {
|
|
195
143
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
144
|
+
let archivedByCall = false;
|
|
196
145
|
await archiveThenDeleteClient({
|
|
197
146
|
workspaceId,
|
|
198
147
|
id,
|
|
199
148
|
adapter: {
|
|
200
149
|
getCurrent: ({ workspaceId: currentWorkspaceId, id: clientId }) => client.clients.get({ workspaceId: currentWorkspaceId, clientId }),
|
|
201
150
|
archive: async ({ workspaceId: currentWorkspaceId, id: clientId, current }) => {
|
|
202
|
-
await client.clients.update({
|
|
151
|
+
await dispatchedWrite(this, client.clients.update({
|
|
203
152
|
workspaceId: currentWorkspaceId,
|
|
204
153
|
clientId,
|
|
205
|
-
body:
|
|
206
|
-
});
|
|
154
|
+
body: clientUpdate.body(current, { archived: true }),
|
|
155
|
+
}));
|
|
156
|
+
archivedByCall = true;
|
|
207
157
|
},
|
|
208
158
|
delete: async ({ workspaceId: currentWorkspaceId, id: clientId }) => {
|
|
209
|
-
|
|
159
|
+
try {
|
|
160
|
+
await dispatchedWrite(this, client.clients.delete({ workspaceId: currentWorkspaceId, clientId }));
|
|
161
|
+
}
|
|
162
|
+
catch (cause) {
|
|
163
|
+
throw new PartialDeleteError(cause, "archived", `clk115 clients get ${id} --json`, archivedByCall ? "archived_by_call" : "already_archived");
|
|
164
|
+
}
|
|
210
165
|
},
|
|
211
166
|
},
|
|
212
167
|
});
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,23 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { printObject, printRecords } from "../output.js";
|
|
1
|
+
import { requireHeaderValue, requireRoute } from "../client.js";
|
|
2
|
+
import { globalFlags, resolveFlags } from "../flags.js";
|
|
3
|
+
import { fixedColumns, printObject, printRecords } from "../output.js";
|
|
5
4
|
import { rootProgram } from "./helpers.js";
|
|
6
5
|
import { leafCommand } from "./leaf-command.js";
|
|
7
6
|
const DEFAULT_CLOCKIFY_BASE_URL = "https://api.clockify.me/api/v1";
|
|
7
|
+
const RECEIPT_KEYS = ["ok", "readiness", "checks", "next"];
|
|
8
|
+
const CHECK_KEYS = ["check", "ok", "status", "source", "value", "recovery"];
|
|
9
|
+
const INSTALL_NODE = "Install Node.js 22.13 or newer";
|
|
8
10
|
export const registerDoctorCommand = (program, services) => {
|
|
9
11
|
leafCommand(program, "doctor", "read")
|
|
10
12
|
.description("Check local CLI configuration without contacting Clockify.")
|
|
11
13
|
.addHelpText("after", "\nExamples:\n" +
|
|
12
14
|
" $ clk115 doctor\n" +
|
|
13
15
|
" $ clk115 doctor --json\n")
|
|
14
|
-
.action(function () {
|
|
16
|
+
.action(async function () {
|
|
15
17
|
const root = rootProgram(this);
|
|
16
18
|
const flags = globalFlags(root);
|
|
19
|
+
const { mode } = resolveFlags(root);
|
|
20
|
+
const asReceipt = mode === "json" || mode === "ndjson";
|
|
21
|
+
const output = fixedColumns(asReceipt ? RECEIPT_KEYS : CHECK_KEYS, resolveFlags(root));
|
|
17
22
|
const config = services.loadConfig(flags);
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
if (output.mode !== "table") {
|
|
23
|
+
const receipt = await buildDoctorReceipt(config, flags, process.env, services);
|
|
24
|
+
if (asReceipt) {
|
|
21
25
|
printObject(receipt, output);
|
|
22
26
|
return;
|
|
23
27
|
}
|
|
@@ -29,62 +33,101 @@ export const registerDoctorCommand = (program, services) => {
|
|
|
29
33
|
value: c.value ?? "",
|
|
30
34
|
recovery: c.recovery ?? "",
|
|
31
35
|
})), output);
|
|
32
|
-
|
|
36
|
+
if (mode === "csv")
|
|
37
|
+
return;
|
|
38
|
+
const { fields: _fields, ...summary } = output;
|
|
39
|
+
printObject({ ok: receipt.ok, readiness: receipt.readiness }, summary);
|
|
33
40
|
for (const step of receipt.next)
|
|
34
41
|
console.log(step);
|
|
35
42
|
});
|
|
36
43
|
};
|
|
37
|
-
function
|
|
44
|
+
async function acceptsBaseUrl(baseUrl) {
|
|
45
|
+
try {
|
|
46
|
+
await requireRoute({ baseUrl });
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const messageOf = (err) => (err instanceof Error ? err.message : String(err));
|
|
54
|
+
function presentKey(key, source, value) {
|
|
55
|
+
try {
|
|
56
|
+
requireHeaderValue(key);
|
|
57
|
+
return { ok: true, status: "present", source, value };
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
return { ok: false, status: "present", source, value, recovery: messageOf(err) };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async function checkApiKey(config, services) {
|
|
64
|
+
if (isPresent(config.apiKey))
|
|
65
|
+
return presentKey(config.apiKey, "env", "configured (redacted)");
|
|
66
|
+
if (config.profile === undefined) {
|
|
67
|
+
return { ok: false, status: "missing", recovery: "Set CLOCKIFY_API_KEY in the process environment, or run `clk115 auth login`." };
|
|
68
|
+
}
|
|
69
|
+
const { storedApiKey, systemCredentialStore } = await import("../credentials.js");
|
|
70
|
+
const login = `Run \`clk115 auth login --profile ${config.profile}\`.`;
|
|
71
|
+
try {
|
|
72
|
+
const key = await storedApiKey(config, services.credentials ?? systemCredentialStore);
|
|
73
|
+
if (key !== undefined)
|
|
74
|
+
return presentKey(key, "profile", `profile ${config.profile} (redacted)`);
|
|
75
|
+
return { ok: false, status: "missing", source: "profile", recovery: login };
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
return { ok: false, status: "missing", source: "profile", recovery: `${messageOf(err)} ${login}` };
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
async function buildDoctorReceipt(config, flags, env, services) {
|
|
38
82
|
const [nodeMajor = 0, nodeMinor = 0] = process.versions.node
|
|
39
83
|
.split(".")
|
|
40
84
|
.map((part) => Number.parseInt(part, 10) || 0);
|
|
41
85
|
const nodeOk = nodeMajor > 22 || (nodeMajor === 22 && nodeMinor >= 13);
|
|
42
|
-
const apiKeySource = sourceFor("apiKey", config, flags, env);
|
|
43
86
|
const workspaceSource = sourceFor("workspaceId", config, flags, env);
|
|
44
87
|
const baseUrlSource = sourceFor("baseUrl", config, flags, env) ?? "default";
|
|
45
88
|
const regionSource = sourceFor("region", config, flags, env) ?? "default";
|
|
46
89
|
const subdomainSource = sourceFor("subdomain", config, flags, env) ?? "default";
|
|
47
|
-
const
|
|
90
|
+
const apiKey = await checkApiKey(config, services);
|
|
48
91
|
const workspaceOk = isPresent(config.workspaceId);
|
|
49
|
-
const baseUrl = config.baseUrl
|
|
50
|
-
|
|
92
|
+
const baseUrl = config.baseUrl === undefined
|
|
93
|
+
? DEFAULT_CLOCKIFY_BASE_URL
|
|
94
|
+
: (await import("clockify-sdk-ts-115/diagnostics")).clockifyDiagnostics({
|
|
95
|
+
baseUrl: config.baseUrl,
|
|
96
|
+
env: {},
|
|
97
|
+
}).checks.baseUrl.value;
|
|
51
98
|
let routingError;
|
|
52
|
-
|
|
99
|
+
let baseUrlOk = true;
|
|
100
|
+
if (config.region !== undefined || config.subdomain !== undefined || config.baseUrl !== undefined) {
|
|
53
101
|
try {
|
|
54
|
-
|
|
102
|
+
await requireRoute(config);
|
|
55
103
|
}
|
|
56
104
|
catch (err) {
|
|
57
|
-
|
|
105
|
+
if (config.region !== undefined || config.subdomain !== undefined) {
|
|
106
|
+
routingError = messageOf(err);
|
|
107
|
+
if (config.subdomain)
|
|
108
|
+
routingError = routingError.replace(JSON.stringify(config.subdomain), '"<redacted>"');
|
|
109
|
+
}
|
|
110
|
+
baseUrlOk = config.baseUrl === undefined || await acceptsBaseUrl(config.baseUrl);
|
|
58
111
|
}
|
|
59
112
|
}
|
|
60
113
|
const regionOk = routingError === undefined;
|
|
61
|
-
const subdomainOk =
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
114
|
+
const subdomainOk = regionOk;
|
|
115
|
+
const readinessState = !nodeOk
|
|
116
|
+
? { kind: "runtime_unsupported", ok: false }
|
|
117
|
+
: apiKey.ok && workspaceOk && regionOk && baseUrlOk
|
|
118
|
+
? { kind: "ready_for_status", ok: true }
|
|
119
|
+
: { kind: "configuration_incomplete", ok: false };
|
|
65
120
|
return {
|
|
66
|
-
ok,
|
|
67
|
-
readiness:
|
|
68
|
-
? "runtime_unsupported"
|
|
69
|
-
: configOk
|
|
70
|
-
? "ready_for_status"
|
|
71
|
-
: "configuration_incomplete",
|
|
121
|
+
ok: readinessState.ok,
|
|
122
|
+
readiness: readinessState.kind,
|
|
72
123
|
checks: {
|
|
73
124
|
node: {
|
|
74
125
|
ok: nodeOk,
|
|
75
126
|
status: nodeOk ? "supported" : "unsupported",
|
|
76
127
|
value: process.versions.node,
|
|
77
|
-
...(nodeOk ? {} : { recovery:
|
|
78
|
-
},
|
|
79
|
-
apiKey: {
|
|
80
|
-
ok: apiKeyOk,
|
|
81
|
-
status: apiKeyOk ? "present" : "missing",
|
|
82
|
-
...(apiKeySource !== undefined ? { source: apiKeySource } : {}),
|
|
83
|
-
...(apiKeyOk ? { value: "configured (redacted)" } : {}),
|
|
84
|
-
...(apiKeyOk
|
|
85
|
-
? {}
|
|
86
|
-
: { recovery: "Set CLOCKIFY_API_KEY in the process environment." }),
|
|
128
|
+
...(nodeOk ? {} : { recovery: `${INSTALL_NODE} before using @apet97/clockify-cli-115.` }),
|
|
87
129
|
},
|
|
130
|
+
apiKey,
|
|
88
131
|
workspaceId: {
|
|
89
132
|
ok: workspaceOk,
|
|
90
133
|
status: workspaceOk ? "present" : "missing",
|
|
@@ -100,11 +143,11 @@ function buildDoctorReceipt(config, flags, env) {
|
|
|
100
143
|
ok: baseUrlOk,
|
|
101
144
|
status: config.baseUrl ? "override" : "default",
|
|
102
145
|
source: baseUrlSource,
|
|
103
|
-
value: baseUrl,
|
|
146
|
+
...(baseUrl !== undefined && { value: baseUrl }),
|
|
104
147
|
...(config.baseUrl
|
|
105
148
|
? {
|
|
106
|
-
recovery:
|
|
107
|
-
?
|
|
149
|
+
recovery: !baseUrlOk
|
|
150
|
+
? "The client will reject it. Use a Clockify API URL or loopback URL without credentials, a query or a fragment."
|
|
108
151
|
: "Use the default Clockify API base URL for real work; keep overrides for mocks or replay.",
|
|
109
152
|
}
|
|
110
153
|
: {}),
|
|
@@ -126,15 +169,15 @@ function buildDoctorReceipt(config, flags, env) {
|
|
|
126
169
|
: {}),
|
|
127
170
|
},
|
|
128
171
|
},
|
|
129
|
-
next: nextSteps({ nodeOk,
|
|
172
|
+
next: nextSteps({ nodeOk, apiKey, workspaceOk, hasBaseUrlOverride: isPresent(config.baseUrl) }),
|
|
130
173
|
};
|
|
131
174
|
}
|
|
132
175
|
function nextSteps(input) {
|
|
133
176
|
const steps = [];
|
|
134
177
|
if (!input.nodeOk)
|
|
135
|
-
steps.push(
|
|
136
|
-
if (!input.
|
|
137
|
-
steps.push(
|
|
178
|
+
steps.push(`${INSTALL_NODE}.`);
|
|
179
|
+
if (!input.apiKey.ok && input.apiKey.recovery !== undefined)
|
|
180
|
+
steps.push(input.apiKey.recovery);
|
|
138
181
|
if (!input.workspaceOk)
|
|
139
182
|
steps.push("Set CLOCKIFY_WORKSPACE_ID or pass --workspace.");
|
|
140
183
|
if (input.hasBaseUrlOverride) {
|
|
@@ -146,46 +189,19 @@ function nextSteps(input) {
|
|
|
146
189
|
}
|
|
147
190
|
return steps;
|
|
148
191
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return "flag";
|
|
158
|
-
if (isPresent(env.CLOCKIFY_WORKSPACE_ID))
|
|
159
|
-
return "env";
|
|
160
|
-
if (isPresent(config.workspaceId))
|
|
161
|
-
return "rc";
|
|
162
|
-
return undefined;
|
|
163
|
-
}
|
|
164
|
-
if (field === "baseUrl") {
|
|
165
|
-
if (isPresent(flags.baseUrl))
|
|
166
|
-
return "flag";
|
|
167
|
-
if (isPresent(env.CLOCKIFY_BASE_URL))
|
|
168
|
-
return "env";
|
|
169
|
-
if (isPresent(config.baseUrl))
|
|
170
|
-
return "rc";
|
|
171
|
-
return undefined;
|
|
172
|
-
}
|
|
173
|
-
if (field === "region") {
|
|
174
|
-
if (isPresent(flags.region))
|
|
175
|
-
return "flag";
|
|
176
|
-
if (isPresent(env.CLOCKIFY_REGION))
|
|
177
|
-
return "env";
|
|
178
|
-
if (isPresent(config.region))
|
|
179
|
-
return "rc";
|
|
192
|
+
const SOURCES = {
|
|
193
|
+
workspaceId: { flag: "workspace", env: "CLOCKIFY_WORKSPACE_ID" },
|
|
194
|
+
baseUrl: { flag: "baseUrl", env: "CLOCKIFY_BASE_URL" },
|
|
195
|
+
region: { flag: "region", env: "CLOCKIFY_REGION" },
|
|
196
|
+
subdomain: { flag: "subdomain", env: "CLOCKIFY_SUBDOMAIN" },
|
|
197
|
+
};
|
|
198
|
+
function sourceFor(field, config, flags, processEnv) {
|
|
199
|
+
if (!isPresent(config[field]))
|
|
180
200
|
return undefined;
|
|
181
|
-
}
|
|
182
|
-
if (isPresent(flags
|
|
201
|
+
const { flag, env } = SOURCES[field];
|
|
202
|
+
if (isPresent(flags[flag]))
|
|
183
203
|
return "flag";
|
|
184
|
-
|
|
185
|
-
return "env";
|
|
186
|
-
if (isPresent(config.subdomain))
|
|
187
|
-
return "rc";
|
|
188
|
-
return undefined;
|
|
204
|
+
return flags.profile === undefined && isPresent(processEnv[env]) ? "env" : "rc";
|
|
189
205
|
}
|
|
190
206
|
function isPresent(value) {
|
|
191
207
|
return typeof value === "string" && value.trim().length > 0;
|
package/dist/commands/entries.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UsageError } from "../failure.js";
|
|
2
2
|
import { printRecords } from "../output.js";
|
|
3
3
|
import { printReceipt } from "../receipt.js";
|
|
4
|
-
import {
|
|
4
|
+
import { dispatchedWrite } from "../write-outcome.js";
|
|
5
|
+
import { clampPageSize, parseIntArg, parseTimeViewMode, promoteDateBoundary, requireCurrentUserId, resolveContext, splitList, TIME_VIEW_MODE_HELP, } from "./helpers.js";
|
|
5
6
|
import { leafCommand } from "./leaf-command.js";
|
|
6
7
|
export const registerEntriesCommand = (program, services) => {
|
|
7
8
|
const entries = program.command("entries").description("Manage time entries.");
|
|
@@ -13,27 +14,36 @@ export const registerEntriesCommand = (program, services) => {
|
|
|
13
14
|
.option("--limit <n>", "Items per page (default 25, max 200).", parseIntArg, 25)
|
|
14
15
|
.option("--page <n>", "Page number (default 1).", parseIntArg, 1)
|
|
15
16
|
.option("--from <date>", "Inclusive start bound (YYYY-MM-DD or RFC3339).")
|
|
16
|
-
.option("--to <date>", "
|
|
17
|
+
.option("--to <date>", "Include this calendar date (YYYY-MM-DD), or exclude the RFC3339 instant itself.")
|
|
17
18
|
.option("--description <text>", "Filter by description substring.")
|
|
19
|
+
.option("--time-view-mode <mode>", TIME_VIEW_MODE_HELP)
|
|
18
20
|
.action(async function (opts) {
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
const start = opts.from ? promoteDateBoundary(opts.from, "from", "start") : undefined;
|
|
22
|
+
let end = opts.to ? promoteDateBoundary(opts.to, "to", "start") : undefined;
|
|
23
|
+
if (end && end !== opts.to) {
|
|
24
|
+
const midnight = new Date(end);
|
|
25
|
+
midnight.setUTCDate(midnight.getUTCDate() + 1);
|
|
26
|
+
end = midnight.getUTCFullYear() > 9999
|
|
27
|
+
? promoteDateBoundary(opts.to, "to", "end")
|
|
28
|
+
: midnight.toISOString().replace(".000Z", "Z");
|
|
24
29
|
}
|
|
30
|
+
const timeViewMode = opts.timeViewMode === undefined ? undefined : parseTimeViewMode(opts.timeViewMode);
|
|
31
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
32
|
+
const userId = await requireCurrentUserId(client);
|
|
25
33
|
const req = {
|
|
26
34
|
workspaceId,
|
|
27
35
|
userId,
|
|
28
36
|
page: opts.page,
|
|
29
37
|
"page-size": clampPageSize(opts.limit, 200),
|
|
30
38
|
};
|
|
31
|
-
if (
|
|
32
|
-
req.start =
|
|
33
|
-
if (
|
|
34
|
-
req.end =
|
|
39
|
+
if (start !== undefined)
|
|
40
|
+
req.start = start;
|
|
41
|
+
if (end !== undefined)
|
|
42
|
+
req.end = end;
|
|
35
43
|
if (opts.description)
|
|
36
44
|
req.description = opts.description;
|
|
45
|
+
if (timeViewMode !== undefined)
|
|
46
|
+
req.timeViewMode = timeViewMode;
|
|
37
47
|
const items = await client.timeEntries.listForUser(req);
|
|
38
48
|
const rows = items.map((raw) => {
|
|
39
49
|
const e = raw;
|
|
@@ -60,7 +70,7 @@ export const registerEntriesCommand = (program, services) => {
|
|
|
60
70
|
.action(async function (opts) {
|
|
61
71
|
const timeEntryIds = splitList(opts.ids);
|
|
62
72
|
if (timeEntryIds.length === 0)
|
|
63
|
-
throw new
|
|
73
|
+
throw new UsageError("--ids needs at least one time-entry ID");
|
|
64
74
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
65
75
|
const items = await client.timeEntries.getMultipleTimeEntries({
|
|
66
76
|
workspaceId,
|
|
@@ -71,6 +81,11 @@ export const registerEntriesCommand = (program, services) => {
|
|
|
71
81
|
description: entry.description ?? "",
|
|
72
82
|
project: entry.projectId ?? "",
|
|
73
83
|
task: entry.taskId ?? "",
|
|
84
|
+
...(opts.hydrated === true && {
|
|
85
|
+
project: entry.project ?? entry.projectId ?? null,
|
|
86
|
+
task: entry.task ?? entry.taskId ?? null,
|
|
87
|
+
tags: entry.tags ?? entry.tagIds ?? [],
|
|
88
|
+
}),
|
|
74
89
|
billable: entry.billable === true,
|
|
75
90
|
start: entry.timeInterval?.start ?? "",
|
|
76
91
|
end: entry.timeInterval?.end ?? "",
|
|
@@ -84,7 +99,7 @@ export const registerEntriesCommand = (program, services) => {
|
|
|
84
99
|
.addHelpText("after", "\nExamples:\n" + " $ clk115 entries delete entry_123\n")
|
|
85
100
|
.action(async function (id) {
|
|
86
101
|
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
87
|
-
await client.timeEntries.delete({ workspaceId, timeEntryId: id });
|
|
102
|
+
await dispatchedWrite(this, client.timeEntries.delete({ workspaceId, timeEntryId: id }));
|
|
88
103
|
printReceipt({
|
|
89
104
|
ok: true,
|
|
90
105
|
action: "entries.delete",
|