@beauraines/toggl-cli 2.6.6 → 2.8.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/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
4
4
 
5
+ ## [2.8.0](https://github.com/beauraines/toggl-cli/compare/v2.7.0...v2.8.0) (2026-02-28)
6
+
7
+
8
+ ### Features
9
+
10
+ * add toggl quota command for API usage reporting ([#227](https://github.com/beauraines/toggl-cli/issues/227)) ([474541f](https://github.com/beauraines/toggl-cli/commit/474541f556f29a753fb7d8c108850f56c8c678d0))
11
+
12
+ ## [2.7.0](https://github.com/beauraines/toggl-cli/compare/v2.6.6...v2.7.0) (2026-02-28)
13
+
14
+
15
+ ### Features
16
+
17
+ * add automatic API quota warning on every command ([#228](https://github.com/beauraines/toggl-cli/issues/228)) ([9c0ce3f](https://github.com/beauraines/toggl-cli/commit/9c0ce3f971e99ef31cbc66bbcff10bffae89a050))
18
+
5
19
  ### [2.6.6](https://github.com/beauraines/toggl-cli/compare/v2.6.5...v2.6.6) (2026-02-28)
6
20
 
7
21
 
package/client.js CHANGED
@@ -1,10 +1,12 @@
1
1
  import dotenv from 'dotenv'
2
2
  import togglClient from 'toggl-client'
3
+ import chalk from 'chalk'
3
4
  import { readConfig } from './config.js'
4
5
  dotenv.config({quiet:true})
5
6
  import debugClient from 'debug'
6
7
  const debug = debugClient('toggl-cli-client')
7
8
 
9
+ const QUOTA_WARNING_THRESHOLD = 5
8
10
 
9
11
  export default async function () {
10
12
  let conf
@@ -27,7 +29,16 @@ export default async function () {
27
29
  process.exit(1)
28
30
  }
29
31
 
32
+ // Wrap request method to warn when API quota is running low
33
+ const originalRequest = client.request.bind(client)
34
+ client.request = async function (...args) {
35
+ const result = await originalRequest(...args)
36
+ if (client.quota && client.quota.remaining !== null && client.quota.remaining <= QUOTA_WARNING_THRESHOLD) {
37
+ const minutes = client.quota.resetsIn ? Math.ceil(client.quota.resetsIn / 60) : '?'
38
+ console.error(chalk.yellow(`\n⚠ API quota low: ${client.quota.remaining} requests remaining (resets in ~${minutes}m)`))
39
+ }
40
+ return result
41
+ }
42
+
30
43
  return client
31
44
  }
32
-
33
-
package/cmds/index.mjs CHANGED
@@ -13,6 +13,7 @@ import * as removeTimeEntry from './removeTimeEntry.mjs'
13
13
  import * as today from './today.mjs'
14
14
  import * as weekly from './weekly.mjs'
15
15
  import * as createConfig from './create-config.mjs'
16
+ import * as quota from './quota.mjs'
16
17
  export const commands = [
17
18
  continueEntry,
18
19
  current,
@@ -20,6 +21,7 @@ export const commands = [
20
21
  ls,
21
22
  me,
22
23
  projects,
24
+ quota,
23
25
  startTimeEntry,
24
26
  stopTimeEntry,
25
27
  addTimeEntry,
package/cmds/quota.mjs ADDED
@@ -0,0 +1,59 @@
1
+ import Client from '../client.js'
2
+ import chalk from 'chalk'
3
+ import { defaultWorkspaceId } from '../utils.js'
4
+
5
+ export const command = 'quota'
6
+ export const desc = 'Displays API quota usage information'
7
+ export const builder = {}
8
+
9
+ function formatQuota(remaining, resetsIn) {
10
+ let remainingDisplay
11
+ if (remaining > 10) {
12
+ remainingDisplay = chalk.green(remaining)
13
+ } else if (remaining > 5) {
14
+ remainingDisplay = chalk.yellow(remaining)
15
+ } else {
16
+ remainingDisplay = chalk.red(remaining)
17
+ }
18
+
19
+ let resetDisplay = ''
20
+ if (resetsIn !== null) {
21
+ const minutes = Math.floor(resetsIn / 60)
22
+ const seconds = resetsIn % 60
23
+ resetDisplay = ` (resets in ${minutes}m ${seconds}s)`
24
+ }
25
+
26
+ return `${remainingDisplay} requests${resetDisplay}`
27
+ }
28
+
29
+ export const handler = async function (argv) {
30
+ const client = await Client()
31
+
32
+ // Call a user-specific endpoint to get the user quota
33
+ await client.user.current()
34
+ const userQuota = client.quota ? { ...client.quota } : null
35
+
36
+ // Call a workspace-scoped endpoint to get the workspace/org quota
37
+ await client.workspaces.projects(defaultWorkspaceId)
38
+ const workspaceQuota = client.quota ? { ...client.quota } : null
39
+
40
+ if (!userQuota && !workspaceQuota) {
41
+ console.log('No API quota information available in the response headers.')
42
+ console.log('The Toggl API may not be returning quota headers yet.')
43
+ return
44
+ }
45
+
46
+ if (workspaceQuota && workspaceQuota.remaining !== null) {
47
+ console.log(`Workspace quota: ${formatQuota(workspaceQuota.remaining, workspaceQuota.resetsIn)}`)
48
+ }
49
+
50
+ if (userQuota && userQuota.remaining !== null) {
51
+ console.log(`User quota: ${formatQuota(userQuota.remaining, userQuota.resetsIn)}`)
52
+ }
53
+
54
+ const low = [userQuota, workspaceQuota].some(q => q && q.remaining !== null && q.remaining <= 5)
55
+ if (low) {
56
+ console.log(chalk.red('\n⚠ Warning: API quota is running low!'))
57
+ console.log(chalk.red('Consider waiting before making more requests.'))
58
+ }
59
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@beauraines/toggl-cli",
3
- "version": "2.6.6",
3
+ "version": "2.8.0",
4
4
  "description": "CLI client for Toggl Time Tracker",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -36,7 +36,7 @@
36
36
  "debug": "^4.3.4",
37
37
  "dotenv": "^17.2.3",
38
38
  "open": "^11.0.0",
39
- "toggl-client": "^3.1.1",
39
+ "toggl-client": "github:beauraines/toggl-client",
40
40
  "yargs": "^18.0.0"
41
41
  },
42
42
  "devDependencies": {