@apet97/clockify-cli-115 0.3.2 → 0.4.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 +13 -4
- package/dist/client.js +33 -0
- package/dist/commands/doctor.js +49 -1
- package/dist/config.js +8 -0
- package/dist/generated/version.js +1 -1
- package/dist/index.js +6 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
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.
|
|
6
|
+
Current release: `0.4.0`. Requires Node.js `>=22.13.0` and
|
|
7
7
|
`clockify-sdk-ts-115 >=0.12.0 <1`.
|
|
8
8
|
|
|
9
9
|
Two binaries, identical behavior:
|
|
@@ -29,18 +29,27 @@ clk115 stop
|
|
|
29
29
|
|
|
30
30
|
In precedence order (highest wins):
|
|
31
31
|
|
|
32
|
-
1. **Command-line flags:** `--workspace`, `--base-url
|
|
32
|
+
1. **Command-line flags:** `--workspace`, `--base-url`, `--region`, `--subdomain`
|
|
33
|
+
(credentials are never accepted on argv)
|
|
33
34
|
2. **Environment variables:** `CLOCKIFY_API_KEY`, `CLOCKIFY_WORKSPACE_ID`,
|
|
34
|
-
optional `CLOCKIFY_BASE_URL` for mock/replay or private gateway tests
|
|
35
|
+
optional `CLOCKIFY_BASE_URL` for mock/replay or private gateway tests,
|
|
36
|
+
optional `CLOCKIFY_REGION`/`CLOCKIFY_SUBDOMAIN` for regional routing
|
|
35
37
|
3. **Rc file:** `~/.clockifyrc.json` (or `clockifyrc.json` in
|
|
36
38
|
`$CLOCKIFY_HOME`)
|
|
37
39
|
|
|
40
|
+
`--region` (`global`, `eu`, `us`, `uk`, `au`, or `developer`) selects a Clockify
|
|
41
|
+
routing profile; `--subdomain` selects a workspace subdomain and requires
|
|
42
|
+
`--region` to be `eu`/`us`/`uk`/`au`. Both are mutually exclusive with
|
|
43
|
+
`--base-url`/`CLOCKIFY_BASE_URL`.
|
|
44
|
+
|
|
38
45
|
Rc file shape:
|
|
39
46
|
|
|
40
47
|
```json
|
|
41
48
|
{
|
|
42
49
|
"workspaceId": "65b382b6…",
|
|
43
|
-
"baseUrl": "https://api.clockify.me/api/v1"
|
|
50
|
+
"baseUrl": "https://api.clockify.me/api/v1",
|
|
51
|
+
"region": "eu",
|
|
52
|
+
"subdomain": "acme"
|
|
44
53
|
}
|
|
45
54
|
```
|
|
46
55
|
|
package/dist/client.js
CHANGED
|
@@ -1,7 +1,40 @@
|
|
|
1
1
|
import { requireApiKey } from "./config.js";
|
|
2
|
+
const REGIONAL_PREFIXES = ["eu", "us", "uk", "au"];
|
|
3
|
+
const KNOWN_REGIONS = ["global", ...REGIONAL_PREFIXES, "developer"];
|
|
4
|
+
export function buildRoutingOptions(region, subdomain) {
|
|
5
|
+
if (region === undefined && subdomain === undefined)
|
|
6
|
+
return undefined;
|
|
7
|
+
if (subdomain !== undefined) {
|
|
8
|
+
if (region === undefined || !REGIONAL_PREFIXES.includes(region)) {
|
|
9
|
+
throw new Error(`--subdomain requires --region to be one of ${REGIONAL_PREFIXES.join(", ")} (got ${JSON.stringify(region)}).`);
|
|
10
|
+
}
|
|
11
|
+
return {
|
|
12
|
+
profile: "subdomain",
|
|
13
|
+
region: region,
|
|
14
|
+
subdomain,
|
|
15
|
+
acknowledgeUnconfirmedRegion: true,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
if (region === "global")
|
|
19
|
+
return { profile: "global" };
|
|
20
|
+
if (!KNOWN_REGIONS.includes(region)) {
|
|
21
|
+
throw new Error(`Unrecognized Clockify region ${JSON.stringify(region)}. Expected one of ${KNOWN_REGIONS.join(", ")}.`);
|
|
22
|
+
}
|
|
23
|
+
return {
|
|
24
|
+
profile: region,
|
|
25
|
+
acknowledgeUnconfirmedRegion: true,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
2
28
|
export async function buildClient(config) {
|
|
3
29
|
const apiKey = requireApiKey(config);
|
|
30
|
+
const routing = buildRoutingOptions(config.region, config.subdomain);
|
|
31
|
+
if (routing !== undefined && config.baseUrl !== undefined) {
|
|
32
|
+
throw new Error("clk115: pass either --region/--subdomain or --base-url, not both -- they configure the same thing two different ways.");
|
|
33
|
+
}
|
|
4
34
|
const { createClockifyClient } = await import("clockify-sdk-ts-115");
|
|
35
|
+
if (routing !== undefined) {
|
|
36
|
+
return createClockifyClient({ apiKey, allowNonClockifyHttpsHost: false, routing });
|
|
37
|
+
}
|
|
5
38
|
return createClockifyClient({
|
|
6
39
|
apiKey,
|
|
7
40
|
allowNonClockifyHttpsHost: false,
|
package/dist/commands/doctor.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { classifyClockifyBaseUrl } from "clockify-sdk-ts-115/create-client";
|
|
2
|
+
import { buildRoutingOptions } from "../client.js";
|
|
2
3
|
import { globalFlags, resolveFlags } from "../index.js";
|
|
3
4
|
import { printObject } from "../output.js";
|
|
4
5
|
import { rootProgram } from "./helpers.js";
|
|
@@ -21,11 +22,24 @@ function buildDoctorReceipt(config, flags, env) {
|
|
|
21
22
|
const apiKeySource = sourceFor("apiKey", config, flags, env);
|
|
22
23
|
const workspaceSource = sourceFor("workspaceId", config, flags, env);
|
|
23
24
|
const baseUrlSource = sourceFor("baseUrl", config, flags, env) ?? "default";
|
|
25
|
+
const regionSource = sourceFor("region", config, flags, env) ?? "default";
|
|
26
|
+
const subdomainSource = sourceFor("subdomain", config, flags, env) ?? "default";
|
|
24
27
|
const apiKeyOk = isPresent(config.apiKey);
|
|
25
28
|
const workspaceOk = isPresent(config.workspaceId);
|
|
26
29
|
const baseUrl = config.baseUrl ?? DEFAULT_CLOCKIFY_BASE_URL;
|
|
27
30
|
const baseUrlClass = config.baseUrl ? classifyClockifyBaseUrl(baseUrl) : undefined;
|
|
28
|
-
|
|
31
|
+
let routingError;
|
|
32
|
+
if (isPresent(config.region) || isPresent(config.subdomain)) {
|
|
33
|
+
try {
|
|
34
|
+
buildRoutingOptions(config.region, config.subdomain);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
routingError = err instanceof Error ? err.message : String(err);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const regionOk = routingError === undefined;
|
|
41
|
+
const subdomainOk = routingError === undefined;
|
|
42
|
+
const configOk = apiKeyOk && workspaceOk && regionOk;
|
|
29
43
|
const ok = nodeOk && configOk;
|
|
30
44
|
return {
|
|
31
45
|
ok,
|
|
@@ -74,6 +88,22 @@ function buildDoctorReceipt(config, flags, env) {
|
|
|
74
88
|
}
|
|
75
89
|
: {}),
|
|
76
90
|
},
|
|
91
|
+
region: {
|
|
92
|
+
ok: regionOk,
|
|
93
|
+
status: config.region ? "override" : "default",
|
|
94
|
+
source: regionSource,
|
|
95
|
+
value: config.region ?? "global",
|
|
96
|
+
...(routingError !== undefined ? { recovery: routingError } : {}),
|
|
97
|
+
},
|
|
98
|
+
subdomain: {
|
|
99
|
+
ok: subdomainOk,
|
|
100
|
+
status: config.subdomain ? "override" : "default",
|
|
101
|
+
source: subdomainSource,
|
|
102
|
+
...(config.subdomain !== undefined ? { value: maskId(config.subdomain) ?? "" } : {}),
|
|
103
|
+
...(routingError !== undefined && isPresent(config.subdomain)
|
|
104
|
+
? { recovery: routingError }
|
|
105
|
+
: {}),
|
|
106
|
+
},
|
|
77
107
|
},
|
|
78
108
|
next: nextSteps({ nodeOk, apiKeyOk, workspaceOk, hasBaseUrlOverride: isPresent(config.baseUrl) }),
|
|
79
109
|
};
|
|
@@ -119,6 +149,24 @@ function sourceFor(field, config, flags, env) {
|
|
|
119
149
|
return "rc";
|
|
120
150
|
return undefined;
|
|
121
151
|
}
|
|
152
|
+
if (field === "region") {
|
|
153
|
+
if (isPresent(flags.region))
|
|
154
|
+
return "flag";
|
|
155
|
+
if (isPresent(env.CLOCKIFY_REGION))
|
|
156
|
+
return "env";
|
|
157
|
+
if (isPresent(config.region))
|
|
158
|
+
return "rc";
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
if (field === "subdomain") {
|
|
162
|
+
if (isPresent(flags.subdomain))
|
|
163
|
+
return "flag";
|
|
164
|
+
if (isPresent(env.CLOCKIFY_SUBDOMAIN))
|
|
165
|
+
return "env";
|
|
166
|
+
if (isPresent(config.subdomain))
|
|
167
|
+
return "rc";
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
122
170
|
return undefined;
|
|
123
171
|
}
|
|
124
172
|
function isPresent(value) {
|
package/dist/config.js
CHANGED
|
@@ -6,10 +6,14 @@ export function loadConfig(flags = {}, env = process.env) {
|
|
|
6
6
|
const apiKey = firstPresent(env.CLOCKIFY_API_KEY);
|
|
7
7
|
const workspaceId = firstPresent(flags.workspace, env.CLOCKIFY_WORKSPACE_ID, file.workspaceId);
|
|
8
8
|
const baseUrl = firstPresent(flags.baseUrl, env.CLOCKIFY_BASE_URL, file.baseUrl);
|
|
9
|
+
const region = firstPresent(flags.region, env.CLOCKIFY_REGION, file.region);
|
|
10
|
+
const subdomain = firstPresent(flags.subdomain, env.CLOCKIFY_SUBDOMAIN, file.subdomain);
|
|
9
11
|
return {
|
|
10
12
|
...(apiKey !== undefined ? { apiKey } : {}),
|
|
11
13
|
...(workspaceId !== undefined ? { workspaceId } : {}),
|
|
12
14
|
...(baseUrl !== undefined ? { baseUrl } : {}),
|
|
15
|
+
...(region !== undefined ? { region } : {}),
|
|
16
|
+
...(subdomain !== undefined ? { subdomain } : {}),
|
|
13
17
|
};
|
|
14
18
|
}
|
|
15
19
|
function firstPresent(...values) {
|
|
@@ -45,6 +49,10 @@ function loadRcFile(env) {
|
|
|
45
49
|
out.workspaceId = parsed.workspaceId;
|
|
46
50
|
if (typeof parsed.baseUrl === "string")
|
|
47
51
|
out.baseUrl = parsed.baseUrl;
|
|
52
|
+
if (typeof parsed.region === "string")
|
|
53
|
+
out.region = parsed.region;
|
|
54
|
+
if (typeof parsed.subdomain === "string")
|
|
55
|
+
out.subdomain = parsed.subdomain;
|
|
48
56
|
return out;
|
|
49
57
|
}
|
|
50
58
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const PACKAGE_VERSION = "0.
|
|
1
|
+
export const PACKAGE_VERSION = "0.4.0";
|
package/dist/index.js
CHANGED
|
@@ -38,6 +38,8 @@ export function buildProgram(services = defaultServices) {
|
|
|
38
38
|
.version(PACKAGE_VERSION)
|
|
39
39
|
.option("--workspace <id>", "Clockify workspace ID (or CLOCKIFY_WORKSPACE_ID env var).")
|
|
40
40
|
.option("--base-url <url>", "Override Clockify API base URL (or CLOCKIFY_BASE_URL env var). Only a Clockify host or a loopback host is accepted; arbitrary hosts are rejected.")
|
|
41
|
+
.option("--region <name>", "Clockify routing region: global, eu, us, uk, au, or developer (or CLOCKIFY_REGION env var). Mutually exclusive with --base-url.")
|
|
42
|
+
.option("--subdomain <label>", "Workspace subdomain for reports routing; requires --region eu/us/uk/au (or CLOCKIFY_SUBDOMAIN env var).")
|
|
41
43
|
.option("--json", "Emit machine-readable JSON instead of human-friendly tables.", false)
|
|
42
44
|
.option("--output <mode>", "Output mode: table, json, or ndjson.")
|
|
43
45
|
.option("--compact", "Print compact JSON without indentation.", false)
|
|
@@ -115,6 +117,10 @@ export function globalFlags(program) {
|
|
|
115
117
|
out.workspace = opts.workspace;
|
|
116
118
|
if (opts.baseUrl)
|
|
117
119
|
out.baseUrl = opts.baseUrl;
|
|
120
|
+
if (opts.region)
|
|
121
|
+
out.region = opts.region;
|
|
122
|
+
if (opts.subdomain)
|
|
123
|
+
out.subdomain = opts.subdomain;
|
|
118
124
|
return out;
|
|
119
125
|
}
|
|
120
126
|
export async function main(argv, services = defaultServices) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apet97/clockify-cli-115",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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>",
|
|
@@ -49,12 +49,12 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"cli-table3": "^0.6.5",
|
|
52
|
-
"commander": "^
|
|
52
|
+
"commander": "^15.0.0",
|
|
53
53
|
"picocolors": "^1.1.1",
|
|
54
54
|
"zod": "^3.25.0"
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
57
|
-
"clockify-sdk-ts-115": ">=0.
|
|
57
|
+
"clockify-sdk-ts-115": ">=0.13.0 <1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/node": "^22",
|