@apet97/clockify-cli-115 0.1.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/LICENSE +21 -0
- package/README.md +216 -0
- package/dist/client.js +10 -0
- package/dist/commands/api.js +187 -0
- package/dist/commands/auditlog.js +50 -0
- package/dist/commands/clients.js +139 -0
- package/dist/commands/doctor.js +137 -0
- package/dist/commands/entries.js +67 -0
- package/dist/commands/expenses.js +205 -0
- package/dist/commands/helpers.js +57 -0
- package/dist/commands/invoices.js +81 -0
- package/dist/commands/log.js +75 -0
- package/dist/commands/projects.js +158 -0
- package/dist/commands/reports.js +134 -0
- package/dist/commands/resolve-refs.js +79 -0
- package/dist/commands/scheduling.js +109 -0
- package/dist/commands/sharedReports.js +174 -0
- package/dist/commands/start.js +65 -0
- package/dist/commands/status.js +66 -0
- package/dist/commands/stop.js +41 -0
- package/dist/commands/tags.js +109 -0
- package/dist/commands/tasks.js +163 -0
- package/dist/commands/timeoff.js +102 -0
- package/dist/commands/types.js +1 -0
- package/dist/commands/users.js +116 -0
- package/dist/commands/webhooks.js +106 -0
- package/dist/completions.js +66 -0
- package/dist/config.js +55 -0
- package/dist/duration.js +70 -0
- package/dist/error-codes.js +268 -0
- package/dist/index.js +171 -0
- package/dist/output.js +144 -0
- package/dist/receipt.js +22 -0
- package/package.json +72 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { wireBody } from "clockify-sdk-ts-115/requests";
|
|
2
|
+
import { assertSafeWebhookUrl } from "clockify-sdk-ts-115/webhooks";
|
|
3
|
+
import { printRecords } from "../output.js";
|
|
4
|
+
import { printReceipt } from "../receipt.js";
|
|
5
|
+
import { resolveContext, splitList } from "./helpers.js";
|
|
6
|
+
export const registerWebhooksCommand = (program, services) => {
|
|
7
|
+
const webhooks = program.command("webhooks").description("Manage outbound webhooks.");
|
|
8
|
+
webhooks
|
|
9
|
+
.command("list")
|
|
10
|
+
.description("List webhooks in the workspace.")
|
|
11
|
+
.option("--type <type>", "Filter by webhook type (e.g. WEBHOOK, ADDON_WEBHOOK).")
|
|
12
|
+
.action(async function (opts) {
|
|
13
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
14
|
+
const req = { workspaceId };
|
|
15
|
+
if (opts.type)
|
|
16
|
+
req.type = opts.type;
|
|
17
|
+
const response = (await client.webhooks.list(wireBody(req)));
|
|
18
|
+
const items = Array.isArray(response) ? response : (response.webhooks ?? []);
|
|
19
|
+
const rows = items.map((raw) => {
|
|
20
|
+
const w = raw;
|
|
21
|
+
return {
|
|
22
|
+
id: w.id ?? "",
|
|
23
|
+
name: w.name ?? "",
|
|
24
|
+
event: w.webhookEvent ?? "",
|
|
25
|
+
url: w.url ?? "",
|
|
26
|
+
enabled: w.enabled !== false,
|
|
27
|
+
triggerSourceType: w.triggerSourceType ?? "",
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
printRecords(rows, output);
|
|
31
|
+
});
|
|
32
|
+
webhooks
|
|
33
|
+
.command("create")
|
|
34
|
+
.description("Create a webhook subscription.")
|
|
35
|
+
.requiredOption("--name <text>", "Webhook label.")
|
|
36
|
+
.requiredOption("--url <url>", "Target URL (HTTPS).")
|
|
37
|
+
.requiredOption("--event <event>", "Webhook event (e.g. NEW_PROJECT, NEW_TIME_ENTRY, NEW_INVOICE).")
|
|
38
|
+
.option("--trigger-source-type <type>", "Trigger source type (e.g. PROJECT_ID, USER_ID).")
|
|
39
|
+
.option("--trigger-source <ids>", "Comma-separated trigger source IDs (required when --trigger-source-type is set).")
|
|
40
|
+
.action(async function (opts) {
|
|
41
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
42
|
+
try {
|
|
43
|
+
assertSafeWebhookUrl(opts.url);
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
46
|
+
throw new Error(`webhooks.create: ${err instanceof Error ? err.message : String(err)}`);
|
|
47
|
+
}
|
|
48
|
+
const body = {
|
|
49
|
+
name: opts.name,
|
|
50
|
+
url: opts.url,
|
|
51
|
+
webhookEvent: opts.event,
|
|
52
|
+
};
|
|
53
|
+
if (opts.triggerSourceType)
|
|
54
|
+
body.triggerSourceType = opts.triggerSourceType;
|
|
55
|
+
if (opts.triggerSource) {
|
|
56
|
+
body.triggerSource = splitList(String(opts.triggerSource));
|
|
57
|
+
}
|
|
58
|
+
const created = (await client.webhooks.create(wireBody({
|
|
59
|
+
workspaceId,
|
|
60
|
+
body,
|
|
61
|
+
})));
|
|
62
|
+
const data = {
|
|
63
|
+
id: created.id ?? "",
|
|
64
|
+
name: created.name ?? "",
|
|
65
|
+
event: created.webhookEvent ?? "",
|
|
66
|
+
url: created.url ?? "",
|
|
67
|
+
enabled: created.enabled !== false,
|
|
68
|
+
};
|
|
69
|
+
printReceipt({
|
|
70
|
+
ok: true,
|
|
71
|
+
action: "webhooks.create",
|
|
72
|
+
entity: "webhook",
|
|
73
|
+
ids: { webhookId: data.id },
|
|
74
|
+
data,
|
|
75
|
+
changed: { created: [{ type: "webhook", id: data.id, name: data.name }] },
|
|
76
|
+
next: [
|
|
77
|
+
{
|
|
78
|
+
command: "clk115 webhooks list --json",
|
|
79
|
+
reason: "Verify the webhook appears.",
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
}, output);
|
|
83
|
+
});
|
|
84
|
+
webhooks
|
|
85
|
+
.command("delete")
|
|
86
|
+
.argument("<id>", "Webhook ID.")
|
|
87
|
+
.description("Delete a webhook subscription.")
|
|
88
|
+
.action(async function (id) {
|
|
89
|
+
const { client, workspaceId, output } = await resolveContext(this, services);
|
|
90
|
+
await client.webhooks.delete({ workspaceId, webhookId: id });
|
|
91
|
+
printReceipt({
|
|
92
|
+
ok: true,
|
|
93
|
+
action: "webhooks.delete",
|
|
94
|
+
entity: "webhook",
|
|
95
|
+
ids: { webhookId: id },
|
|
96
|
+
data: { id, deleted: true, message: `deleted webhook ${id}` },
|
|
97
|
+
changed: { deleted: [{ type: "webhook", id }] },
|
|
98
|
+
next: [
|
|
99
|
+
{
|
|
100
|
+
command: "clk115 webhooks list --json",
|
|
101
|
+
reason: "Verify the webhook no longer appears.",
|
|
102
|
+
},
|
|
103
|
+
],
|
|
104
|
+
}, output);
|
|
105
|
+
});
|
|
106
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export const COMMANDS = [
|
|
2
|
+
"api",
|
|
3
|
+
"status",
|
|
4
|
+
"doctor",
|
|
5
|
+
"start",
|
|
6
|
+
"stop",
|
|
7
|
+
"log",
|
|
8
|
+
"entries",
|
|
9
|
+
"projects",
|
|
10
|
+
"clients",
|
|
11
|
+
"tasks",
|
|
12
|
+
"tags",
|
|
13
|
+
"webhooks",
|
|
14
|
+
"invoices",
|
|
15
|
+
"expenses",
|
|
16
|
+
"timeoff",
|
|
17
|
+
"scheduling",
|
|
18
|
+
"audit-log",
|
|
19
|
+
"reports",
|
|
20
|
+
"shared-reports",
|
|
21
|
+
"users",
|
|
22
|
+
"completion",
|
|
23
|
+
"help",
|
|
24
|
+
];
|
|
25
|
+
export function renderCompletion(shell) {
|
|
26
|
+
const commands = COMMANDS.join(" ");
|
|
27
|
+
if (shell === "zsh")
|
|
28
|
+
return renderZsh(commands);
|
|
29
|
+
if (shell === "bash")
|
|
30
|
+
return renderBash(commands);
|
|
31
|
+
return renderFish();
|
|
32
|
+
}
|
|
33
|
+
export function parseCompletionShell(value) {
|
|
34
|
+
const shell = (value ?? "zsh").toLowerCase();
|
|
35
|
+
if (shell === "bash" || shell === "zsh" || shell === "fish")
|
|
36
|
+
return shell;
|
|
37
|
+
throw new Error("completion shell must be one of: bash, zsh, fish");
|
|
38
|
+
}
|
|
39
|
+
function renderZsh(commands) {
|
|
40
|
+
return `#compdef clk115 clockify115
|
|
41
|
+
# Generated by @apet97/clockify-cli-115.
|
|
42
|
+
_clk115() {
|
|
43
|
+
local -a commands
|
|
44
|
+
commands=(${commands})
|
|
45
|
+
_describe 'command' commands
|
|
46
|
+
}
|
|
47
|
+
compdef _clk115 clk115
|
|
48
|
+
compdef _clk115 clockify115
|
|
49
|
+
`;
|
|
50
|
+
}
|
|
51
|
+
function renderBash(commands) {
|
|
52
|
+
return `_clk115_completion() {
|
|
53
|
+
local cur
|
|
54
|
+
cur="\${COMP_WORDS[COMP_CWORD]}"
|
|
55
|
+
COMPREPLY=( $(compgen -W "${commands}" -- "$cur") )
|
|
56
|
+
}
|
|
57
|
+
complete -F _clk115_completion clk115
|
|
58
|
+
complete -F _clk115_completion clockify115
|
|
59
|
+
`;
|
|
60
|
+
}
|
|
61
|
+
function renderFish() {
|
|
62
|
+
return COMMANDS.map((command) => `complete -c clk115 -f -a ${command}`).join("\n") +
|
|
63
|
+
"\n" +
|
|
64
|
+
COMMANDS.map((command) => `complete -c clockify115 -f -a ${command}`).join("\n") +
|
|
65
|
+
"\n";
|
|
66
|
+
}
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
export function loadConfig(flags = {}, env = process.env) {
|
|
5
|
+
const file = loadRcFile(env);
|
|
6
|
+
const apiKey = firstPresent(flags.apiKey, env.CLOCKIFY_API_KEY, file.apiKey);
|
|
7
|
+
const workspaceId = firstPresent(flags.workspace, env.CLOCKIFY_WORKSPACE_ID, file.workspaceId);
|
|
8
|
+
const baseUrl = firstPresent(flags.baseUrl, env.CLOCKIFY_BASE_URL, file.baseUrl);
|
|
9
|
+
return {
|
|
10
|
+
...(apiKey !== undefined ? { apiKey } : {}),
|
|
11
|
+
...(workspaceId !== undefined ? { workspaceId } : {}),
|
|
12
|
+
...(baseUrl !== undefined ? { baseUrl } : {}),
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
function firstPresent(...values) {
|
|
16
|
+
return values.find((value) => typeof value === "string" && value.trim().length > 0);
|
|
17
|
+
}
|
|
18
|
+
export function requireApiKey(config) {
|
|
19
|
+
if (!config.apiKey) {
|
|
20
|
+
throw new Error("Clockify API key not set. Provide --api-key, set CLOCKIFY_API_KEY, or add `apiKey` to ~/.clockifyrc.json.");
|
|
21
|
+
}
|
|
22
|
+
return config.apiKey;
|
|
23
|
+
}
|
|
24
|
+
export function requireWorkspaceId(config) {
|
|
25
|
+
if (!config.workspaceId) {
|
|
26
|
+
throw new Error("Clockify workspace ID not set. Provide --workspace, set CLOCKIFY_WORKSPACE_ID, or add `workspaceId` to ~/.clockifyrc.json.");
|
|
27
|
+
}
|
|
28
|
+
return config.workspaceId;
|
|
29
|
+
}
|
|
30
|
+
function loadRcFile(env) {
|
|
31
|
+
const root = env.CLOCKIFY_HOME ?? homedir();
|
|
32
|
+
const candidates = [join(root, "clockifyrc.json"), join(root, ".clockifyrc.json")];
|
|
33
|
+
for (const path of candidates) {
|
|
34
|
+
if (!existsSync(path)) {
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
const raw = readFileSync(path, "utf8");
|
|
39
|
+
const parsed = JSON.parse(raw);
|
|
40
|
+
const out = {};
|
|
41
|
+
if (typeof parsed.apiKey === "string")
|
|
42
|
+
out.apiKey = parsed.apiKey;
|
|
43
|
+
if (typeof parsed.workspaceId === "string")
|
|
44
|
+
out.workspaceId = parsed.workspaceId;
|
|
45
|
+
if (typeof parsed.baseUrl === "string")
|
|
46
|
+
out.baseUrl = parsed.baseUrl;
|
|
47
|
+
return out;
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
51
|
+
throw new Error(`failed to read Clockify rc file ${path}: ${reason}`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return {};
|
|
55
|
+
}
|
package/dist/duration.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export function parseDuration(input) {
|
|
2
|
+
const trimmed = input.trim();
|
|
3
|
+
if (trimmed === "") {
|
|
4
|
+
throw new Error("duration is empty");
|
|
5
|
+
}
|
|
6
|
+
if (/^PT/i.test(trimmed)) {
|
|
7
|
+
return parseIsoDuration(trimmed);
|
|
8
|
+
}
|
|
9
|
+
if (/^\d+(?:\.\d+)?$/.test(trimmed)) {
|
|
10
|
+
return Math.round(Number(trimmed) * 60);
|
|
11
|
+
}
|
|
12
|
+
const compact = trimmed.replace(/\s+/g, "");
|
|
13
|
+
const re = /(\d+(?:\.\d+)?)([dhms])/gi;
|
|
14
|
+
let total = 0;
|
|
15
|
+
let consumed = 0;
|
|
16
|
+
let match;
|
|
17
|
+
while ((match = re.exec(compact)) !== null) {
|
|
18
|
+
const value = Number(match[1]);
|
|
19
|
+
const unit = (match[2] ?? "").toLowerCase();
|
|
20
|
+
total += value * unitToSeconds(unit);
|
|
21
|
+
consumed += match[0].length;
|
|
22
|
+
}
|
|
23
|
+
if (consumed === 0 || consumed < compact.length) {
|
|
24
|
+
throw new Error(`cannot parse duration ${JSON.stringify(input)}; use forms like "1h30m", "45m", "90", or ISO "PT1H30M"`);
|
|
25
|
+
}
|
|
26
|
+
return Math.round(total);
|
|
27
|
+
}
|
|
28
|
+
function parseIsoDuration(input) {
|
|
29
|
+
const re = /^PT(?:(\d+(?:\.\d+)?)H)?(?:(\d+(?:\.\d+)?)M)?(?:(\d+(?:\.\d+)?)S)?$/i;
|
|
30
|
+
const match = re.exec(input);
|
|
31
|
+
if (!match || (match[1] == null && match[2] == null && match[3] == null)) {
|
|
32
|
+
throw new Error(`cannot parse ISO duration ${JSON.stringify(input)}`);
|
|
33
|
+
}
|
|
34
|
+
const hours = match[1] != null ? Number(match[1]) : 0;
|
|
35
|
+
const minutes = match[2] != null ? Number(match[2]) : 0;
|
|
36
|
+
const seconds = match[3] != null ? Number(match[3]) : 0;
|
|
37
|
+
return Math.round(hours * 3600 + minutes * 60 + seconds);
|
|
38
|
+
}
|
|
39
|
+
function unitToSeconds(unit) {
|
|
40
|
+
switch (unit) {
|
|
41
|
+
case "d":
|
|
42
|
+
return 86_400;
|
|
43
|
+
case "h":
|
|
44
|
+
return 3_600;
|
|
45
|
+
case "m":
|
|
46
|
+
return 60;
|
|
47
|
+
case "s":
|
|
48
|
+
return 1;
|
|
49
|
+
default:
|
|
50
|
+
throw new Error(`unknown duration unit ${JSON.stringify(unit)}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export function formatIsoDuration(iso) {
|
|
54
|
+
if (!iso) {
|
|
55
|
+
return "0s";
|
|
56
|
+
}
|
|
57
|
+
const re = /^PT(?:(\d+(?:\.\d+)?)H)?(?:(\d+(?:\.\d+)?)M)?(?:(\d+(?:\.\d+)?)S)?$/i;
|
|
58
|
+
const match = re.exec(iso);
|
|
59
|
+
if (!match) {
|
|
60
|
+
return iso;
|
|
61
|
+
}
|
|
62
|
+
const parts = [];
|
|
63
|
+
if (match[1])
|
|
64
|
+
parts.push(`${Number(match[1])}h`);
|
|
65
|
+
if (match[2])
|
|
66
|
+
parts.push(`${Number(match[2])}m`);
|
|
67
|
+
if (match[3])
|
|
68
|
+
parts.push(`${Number(match[3])}s`);
|
|
69
|
+
return parts.length > 0 ? parts.join("") : "0s";
|
|
70
|
+
}
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
export const CLOCKIFY_ERROR_CODES = [
|
|
2
|
+
{
|
|
3
|
+
"code": "invalid_request",
|
|
4
|
+
"httpStatus": [
|
|
5
|
+
400
|
|
6
|
+
],
|
|
7
|
+
"retry": false,
|
|
8
|
+
"surfaces": [
|
|
9
|
+
"sdk",
|
|
10
|
+
"cli",
|
|
11
|
+
"mcp"
|
|
12
|
+
],
|
|
13
|
+
"meaning": "The request is malformed, missing required fields, or locally invalid before Clockify accepts it.",
|
|
14
|
+
"recovery": "Fix the request fields, IDs, dates, pagination values, or enum values, then retry.",
|
|
15
|
+
"reachable": true
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"code": "auth_or_permission",
|
|
19
|
+
"httpStatus": [
|
|
20
|
+
401,
|
|
21
|
+
403
|
|
22
|
+
],
|
|
23
|
+
"retry": false,
|
|
24
|
+
"surfaces": [
|
|
25
|
+
"sdk",
|
|
26
|
+
"cli",
|
|
27
|
+
"mcp"
|
|
28
|
+
],
|
|
29
|
+
"meaning": "The token is missing, invalid, expired, pointed at the wrong workspace, or lacks permission for the operation.",
|
|
30
|
+
"recovery": "Check CLOCKIFY_API_KEY or addon token, workspace ID, and the user's Clockify role or plan permissions.",
|
|
31
|
+
"reachable": true
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"code": "feature_unavailable",
|
|
35
|
+
"httpStatus": [
|
|
36
|
+
402
|
|
37
|
+
],
|
|
38
|
+
"retry": false,
|
|
39
|
+
"surfaces": [
|
|
40
|
+
"cli",
|
|
41
|
+
"mcp"
|
|
42
|
+
],
|
|
43
|
+
"meaning": "The endpoint exists but the workspace plan or feature configuration does not expose it.",
|
|
44
|
+
"recovery": "Use a supported workspace plan, skip the gated workflow, or fall back to a lower-level read operation.",
|
|
45
|
+
"reachable": true
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
"code": "not_found",
|
|
49
|
+
"httpStatus": [
|
|
50
|
+
404
|
|
51
|
+
],
|
|
52
|
+
"retry": false,
|
|
53
|
+
"surfaces": [
|
|
54
|
+
"sdk",
|
|
55
|
+
"cli",
|
|
56
|
+
"mcp"
|
|
57
|
+
],
|
|
58
|
+
"meaning": "The requested object does not exist, is archived/deleted, or is outside the active workspace.",
|
|
59
|
+
"recovery": "List the resource again, use returned IDs instead of names, and confirm the workspace ID.",
|
|
60
|
+
"reachable": true
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
"code": "conflict",
|
|
64
|
+
"httpStatus": [
|
|
65
|
+
409
|
|
66
|
+
],
|
|
67
|
+
"retry": false,
|
|
68
|
+
"surfaces": [
|
|
69
|
+
"sdk",
|
|
70
|
+
"cli",
|
|
71
|
+
"mcp"
|
|
72
|
+
],
|
|
73
|
+
"meaning": "Clockify rejected the write because it conflicts with existing state, uniqueness, or a concurrent update.",
|
|
74
|
+
"recovery": "Fetch current state, reuse the existing object when appropriate, or retry with a different name or payload.",
|
|
75
|
+
"reachable": true
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"code": "rate_limited",
|
|
79
|
+
"httpStatus": [
|
|
80
|
+
429
|
|
81
|
+
],
|
|
82
|
+
"retry": true,
|
|
83
|
+
"surfaces": [
|
|
84
|
+
"sdk",
|
|
85
|
+
"cli",
|
|
86
|
+
"mcp"
|
|
87
|
+
],
|
|
88
|
+
"meaning": "Clockify rate-limited the caller.",
|
|
89
|
+
"recovery": "Wait for Retry-After or X-RateLimit-Reset when present; otherwise retry with exponential backoff.",
|
|
90
|
+
"reachable": true
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
"code": "clockify_upstream_error",
|
|
94
|
+
"httpStatus": [
|
|
95
|
+
500,
|
|
96
|
+
502,
|
|
97
|
+
503,
|
|
98
|
+
504
|
|
99
|
+
],
|
|
100
|
+
"retry": true,
|
|
101
|
+
"surfaces": [
|
|
102
|
+
"sdk",
|
|
103
|
+
"cli",
|
|
104
|
+
"mcp"
|
|
105
|
+
],
|
|
106
|
+
"meaning": "Clockify returned a server-side or temporary upstream failure.",
|
|
107
|
+
"recovery": "Retry idempotent reads/writes with backoff; preserve request IDs for support/debugging.",
|
|
108
|
+
"reachable": true
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
"code": "connection_error",
|
|
112
|
+
"httpStatus": [],
|
|
113
|
+
"retry": true,
|
|
114
|
+
"surfaces": [
|
|
115
|
+
"sdk",
|
|
116
|
+
"cli",
|
|
117
|
+
"mcp"
|
|
118
|
+
],
|
|
119
|
+
"meaning": "The process could not reach Clockify before receiving an HTTP response.",
|
|
120
|
+
"recovery": "Check network, proxy, DNS, TLS, base URL, and retry with backoff.",
|
|
121
|
+
"reachable": true
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
"code": "aborted",
|
|
125
|
+
"httpStatus": [],
|
|
126
|
+
"retry": false,
|
|
127
|
+
"surfaces": [
|
|
128
|
+
"sdk",
|
|
129
|
+
"cli",
|
|
130
|
+
"mcp"
|
|
131
|
+
],
|
|
132
|
+
"meaning": "The caller cancelled the operation with an AbortSignal or equivalent stop request.",
|
|
133
|
+
"recovery": "Do not retry automatically; surface cancellation to the caller.",
|
|
134
|
+
"reachable": true
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
"code": "rate_limited_retry_after",
|
|
138
|
+
"httpStatus": [],
|
|
139
|
+
"retry": true,
|
|
140
|
+
"surfaces": [
|
|
141
|
+
"sdk",
|
|
142
|
+
"cli",
|
|
143
|
+
"mcp"
|
|
144
|
+
],
|
|
145
|
+
"meaning": "Clockify returned 429 with a Retry-After or X-RateLimit-Reset header naming when the caller may resume.",
|
|
146
|
+
"recovery": "Read the Retry-After seconds or X-RateLimit-Reset epoch from response headers, wait that long, then retry the same request once.",
|
|
147
|
+
"reachable": true
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
"code": "addon_token_restricted",
|
|
151
|
+
"httpStatus": [],
|
|
152
|
+
"retry": false,
|
|
153
|
+
"surfaces": [
|
|
154
|
+
"sdk",
|
|
155
|
+
"mcp"
|
|
156
|
+
],
|
|
157
|
+
"meaning": "An X-Addon-Token request reached an endpoint outside the add-on token's allowed surface.",
|
|
158
|
+
"recovery": "Use a user API key for that endpoint, or restrict the add-on workflow to endpoints its token can call.",
|
|
159
|
+
"reachable": true
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
"code": "host_routing_required",
|
|
163
|
+
"httpStatus": [],
|
|
164
|
+
"retry": false,
|
|
165
|
+
"surfaces": [
|
|
166
|
+
"sdk",
|
|
167
|
+
"cli",
|
|
168
|
+
"mcp"
|
|
169
|
+
],
|
|
170
|
+
"meaning": "Reports, audit-log, or expense-report operations were sent to the default API host instead of their dedicated Clockify host.",
|
|
171
|
+
"recovery": "Let the typed SDK method pick its per-operation host, or pass the matching reports/audit-log base URL explicitly.",
|
|
172
|
+
"reachable": false
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"code": "active_resource_delete_blocked",
|
|
176
|
+
"httpStatus": [],
|
|
177
|
+
"retry": false,
|
|
178
|
+
"surfaces": [
|
|
179
|
+
"sdk",
|
|
180
|
+
"cli",
|
|
181
|
+
"mcp"
|
|
182
|
+
],
|
|
183
|
+
"meaning": "Clockify rejected a bare DELETE of an active project, task, or client before the object could be removed.",
|
|
184
|
+
"recovery": "Archive the project/client first, or mark a task done first, then issue the delete.",
|
|
185
|
+
"reachable": true
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
"code": "dead_route",
|
|
189
|
+
"httpStatus": [],
|
|
190
|
+
"retry": false,
|
|
191
|
+
"surfaces": [
|
|
192
|
+
"sdk",
|
|
193
|
+
"cli",
|
|
194
|
+
"mcp"
|
|
195
|
+
],
|
|
196
|
+
"meaning": "A documented Clockify route is not served and returns a static-resource 404 or equivalent unsupported response.",
|
|
197
|
+
"recovery": "Use the replacement path recorded in the evidence ledger and treat the response as a quarantined route, not a transient missing object.",
|
|
198
|
+
"reachable": false
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"code": "name_reserved_after_delete",
|
|
202
|
+
"httpStatus": [],
|
|
203
|
+
"retry": false,
|
|
204
|
+
"surfaces": [
|
|
205
|
+
"sdk",
|
|
206
|
+
"cli",
|
|
207
|
+
"mcp"
|
|
208
|
+
],
|
|
209
|
+
"meaning": "A project, tag, or client name stayed reserved briefly after deletion, so an immediate recreate with the same name was rejected.",
|
|
210
|
+
"recovery": "Wait for the reservation window, reuse the existing object when present, or create the new entity with a distinct name.",
|
|
211
|
+
"reachable": false
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"code": "error",
|
|
215
|
+
"httpStatus": [],
|
|
216
|
+
"retry": false,
|
|
217
|
+
"surfaces": [
|
|
218
|
+
"cli",
|
|
219
|
+
"mcp"
|
|
220
|
+
],
|
|
221
|
+
"meaning": "Unknown local/runtime failure that does not fit a more specific code yet.",
|
|
222
|
+
"recovery": "Preserve the message and request ID if available, then classify the failure into a stable code before broadening behavior.",
|
|
223
|
+
"reachable": true
|
|
224
|
+
},
|
|
225
|
+
{
|
|
226
|
+
"code": "setup_required",
|
|
227
|
+
"httpStatus": [],
|
|
228
|
+
"retry": false,
|
|
229
|
+
"surfaces": [
|
|
230
|
+
"mcp"
|
|
231
|
+
],
|
|
232
|
+
"meaning": "The MCP server started but required credentials (CLOCKIFY_API_KEY and/or CLOCKIFY_WORKSPACE_ID) are not set, so no Clockify call can be made yet.",
|
|
233
|
+
"recovery": "Set CLOCKIFY_API_KEY and CLOCKIFY_WORKSPACE_ID in the MCP client's env block, then restart the server. Get the API key from Clockify Profile Settings -> API; the workspace ID is in the workspace URL.",
|
|
234
|
+
"reachable": true
|
|
235
|
+
}
|
|
236
|
+
];
|
|
237
|
+
export function errorCodeForStatus(status) {
|
|
238
|
+
if (status == null)
|
|
239
|
+
return undefined;
|
|
240
|
+
return CLOCKIFY_ERROR_CODES.find((entry) => entry.httpStatus.includes(status))?.code;
|
|
241
|
+
}
|
|
242
|
+
export function errorCodeForMessage(message) {
|
|
243
|
+
if (/does(?:n'?t| not) (?:belong to|exist)/i.test(message))
|
|
244
|
+
return "not_found";
|
|
245
|
+
if (/(unauthorized|forbidden|permission|api[\s_-]?key|addon[\s_-]?token|CLOCKIFY_API_KEY|CLOCKIFY_ADDON_TOKEN)/i.test(message))
|
|
246
|
+
return "auth_or_permission";
|
|
247
|
+
if (/(required|provide|missing|invalid|unknown option|unknown command|could not parse|not valid|must use|must not|confirmation token)/i.test(message)) {
|
|
248
|
+
return "invalid_request";
|
|
249
|
+
}
|
|
250
|
+
if (/not found/i.test(message))
|
|
251
|
+
return "not_found";
|
|
252
|
+
if (/(rate.?limit|too many requests)/i.test(message))
|
|
253
|
+
return "rate_limited";
|
|
254
|
+
if (/(network|fetch failed|econnreset|dns|tls)/i.test(message))
|
|
255
|
+
return "connection_error";
|
|
256
|
+
if (/(abort|cancel)/i.test(message))
|
|
257
|
+
return "aborted";
|
|
258
|
+
return "error";
|
|
259
|
+
}
|
|
260
|
+
export function errorCodeEntry(code) {
|
|
261
|
+
return CLOCKIFY_ERROR_CODES.find((entry) => entry.code === code) ?? CLOCKIFY_ERROR_CODES[0];
|
|
262
|
+
}
|
|
263
|
+
export function recoveryForCode(code) {
|
|
264
|
+
return errorCodeEntry(code).recovery;
|
|
265
|
+
}
|
|
266
|
+
export function retryableForCode(code) {
|
|
267
|
+
return errorCodeEntry(code).retry;
|
|
268
|
+
}
|