@apet97/clockify-cli-115 5.0.3 → 6.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.
Files changed (40) hide show
  1. package/README.md +96 -26
  2. package/dist/client.js +18 -15
  3. package/dist/closed-pipe.js +3 -0
  4. package/dist/commands/api.js +182 -61
  5. package/dist/commands/approvals.js +9 -7
  6. package/dist/commands/auditlog.js +11 -8
  7. package/dist/commands/balanceAssignment.js +10 -8
  8. package/dist/commands/clients.js +16 -7
  9. package/dist/commands/doctor.js +42 -25
  10. package/dist/commands/entries.js +29 -14
  11. package/dist/commands/expenses.js +64 -22
  12. package/dist/commands/helpers.js +28 -7
  13. package/dist/commands/invoices.js +12 -16
  14. package/dist/commands/leaf-command.js +8 -0
  15. package/dist/commands/log.js +4 -2
  16. package/dist/commands/projects.js +18 -9
  17. package/dist/commands/reports.js +73 -23
  18. package/dist/commands/resolve-refs.js +30 -53
  19. package/dist/commands/scheduling.js +94 -40
  20. package/dist/commands/shared-report-body.js +205 -0
  21. package/dist/commands/sharedReports.js +19 -215
  22. package/dist/commands/start.js +6 -4
  23. package/dist/commands/status.js +55 -19
  24. package/dist/commands/stop.js +15 -17
  25. package/dist/commands/tags.js +6 -4
  26. package/dist/commands/tasks.js +18 -23
  27. package/dist/commands/timeoff.js +23 -16
  28. package/dist/commands/users.js +7 -5
  29. package/dist/commands/webhooks.js +14 -12
  30. package/dist/completions.js +290 -55
  31. package/dist/config.js +10 -6
  32. package/dist/duration.js +5 -4
  33. package/dist/error-codes.js +34 -6
  34. package/dist/failure.js +87 -0
  35. package/dist/flags.js +74 -0
  36. package/dist/generated/version.js +1 -1
  37. package/dist/index.js +41 -105
  38. package/dist/output.js +62 -28
  39. package/dist/write-outcome.js +84 -0
  40. package/package.json +3 -3
@@ -0,0 +1,84 @@
1
+ import { isMutationCommand } from "./commands/leaf-command.js";
2
+ const attempts = new WeakMap();
3
+ const observedTransports = new WeakSet();
4
+ function applied(progress) {
5
+ return progress.kind === "resolved" || (progress.kind === "answered" && isSuccess(progress.status));
6
+ }
7
+ function isSuccess(status) {
8
+ return status >= 200 && status < 300;
9
+ }
10
+ function beginAttempt(command) {
11
+ const previous = attempts.get(command);
12
+ const attempt = {
13
+ afterAppliedWrite: previous !== undefined && (previous.afterAppliedWrite || applied(previous.progress)),
14
+ progress: { kind: "sent" },
15
+ };
16
+ attempts.set(command, attempt);
17
+ return attempt;
18
+ }
19
+ export function observeWriteTransport(command) {
20
+ observedTransports.add(command);
21
+ return async (input, init) => {
22
+ const method = init?.method ?? (input instanceof Request ? input.method : "GET");
23
+ if (method === "GET" || method === "HEAD" || method === "OPTIONS")
24
+ return fetch(input, init);
25
+ const attempt = beginAttempt(command);
26
+ const response = await fetch(input, init);
27
+ attempt.progress = { kind: "answered", status: response.status };
28
+ return response;
29
+ };
30
+ }
31
+ function hasRawResponse(request) {
32
+ return (request !== undefined && "withRawResponse" in request && typeof request.withRawResponse === "function");
33
+ }
34
+ export async function dispatchedWrite(command, request) {
35
+ if (observedTransports.has(command))
36
+ return await request;
37
+ const attempt = beginAttempt(command);
38
+ if (hasRawResponse(request)) {
39
+ const { data, rawResponse } = await request.withRawResponse();
40
+ attempt.progress = { kind: "answered", status: rawResponse.status };
41
+ return data;
42
+ }
43
+ const data = await request;
44
+ attempt.progress = data instanceof Response ? { kind: "answered", status: data.status } : { kind: "resolved" };
45
+ return data;
46
+ }
47
+ export function failureStatus(cause) {
48
+ if (cause === null || typeof cause !== "object")
49
+ return undefined;
50
+ if ("statusCode" in cause && typeof cause.statusCode === "number")
51
+ return cause.statusCode;
52
+ if ("status" in cause && typeof cause.status === "number")
53
+ return cause.status;
54
+ return undefined;
55
+ }
56
+ export async function writeFailure(command, cause) {
57
+ if (!command || !isMutationCommand(command))
58
+ return undefined;
59
+ const attempt = attempts.get(command);
60
+ const status = failureStatus(cause) ?? (attempt?.progress.kind === "answered" ? attempt.progress.status : undefined);
61
+ const stage = await writeStage(attempt, cause, status);
62
+ const replaySafe = stage === "before_dispatch" || stage === "dispatched_rejected";
63
+ return {
64
+ stage,
65
+ replaySafe,
66
+ ...(status !== undefined && { status }),
67
+ ...(!replaySafe && {
68
+ retryable: false,
69
+ recovery: stage === "applied_render_failed"
70
+ ? "The write succeeded. Read back the affected records instead of repeating the command."
71
+ : "Read back the affected records before repeating the command. The write may already have applied.",
72
+ }),
73
+ };
74
+ }
75
+ async function writeStage(attempt, cause, status) {
76
+ if (attempt === undefined)
77
+ return "before_dispatch";
78
+ if (applied(attempt.progress) || (status !== undefined && isSuccess(status)))
79
+ return "applied_render_failed";
80
+ if (attempt.afterAppliedWrite)
81
+ return "partially_applied";
82
+ const { classifyWriteOutcome } = await import("clockify-sdk-ts-115/errors");
83
+ return classifyWriteOutcome(cause) === "definitely-failed" ? "dispatched_rejected" : "dispatched_unknown";
84
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@apet97/clockify-cli-115",
3
- "version": "5.0.3",
3
+ "version": "6.0.0",
4
4
  "description": "Unofficial, community-built \u2014 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\u0107 <petkovic.aleksandar037@gmail.com>",
@@ -54,14 +54,14 @@
54
54
  "zod": "^4.4.3"
55
55
  },
56
56
  "peerDependencies": {
57
- "clockify-sdk-ts-115": "^5"
57
+ "clockify-sdk-ts-115": "^6.0.0"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/node": "^22",
61
61
  "@vitest/coverage-v8": "^4.1.10",
62
62
  "clockify-sdk-ts-115": "*",
63
63
  "eslint": "^10.8.1",
64
- "eslint-plugin-import-x": "^4.17.1",
64
+ "eslint-plugin-import-x": "^4.18.1",
65
65
  "tsx": "^4.23.12",
66
66
  "typescript": "^7.0.2",
67
67
  "typescript-eslint": "^8.67.0",