@ever-teams/cli 0.0.0-stage → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022-present Ever Co. LTD.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,241 @@
1
- # Temporary Holding Version
1
+ # @ever-teams/cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The Ever Teams command line: start and stop your timer, see your day, add time you worked without the timer, and
4
+ export your time entries as CSV or JSON, from a terminal or a script. It works with your own time, signs in once with
5
+ a personal API token, and runs on Node 26 or later. It talks to the API only through the typed client
6
+ [`@ever-teams/api`](https://github.com/ever-co/ever-teams/tree/develop/packages/api#readme).
7
+
8
+ ## Quick start
9
+
10
+ 1. In the web app, open **Settings > API tokens** and create a personal API token. Copy it.
11
+ 2. Install the command line, sign in, and start your timer:
12
+
13
+ ```sh
14
+ npm install --global @ever-teams/cli
15
+ ever-teams login
16
+ ever-teams start
17
+ ```
18
+
19
+ `ever-teams login` asks for the token and hides it while you paste it. It checks the token once with the server, then
20
+ keeps it for the next commands. It signs in to the hosted service (`https://api.ever.team/api`); for your own server,
21
+ give its API address, which ends with `/api`:
22
+
23
+ ```sh
24
+ ever-teams login --api-url https://teams.example.com/api
25
+ ```
26
+
27
+ Then `ever-teams status` shows the running timer and `ever-teams stop` stops it.
28
+
29
+ The server must accept personal API tokens: its administrator turns them on with `GAUZY_USER_API_TOKENS_ENABLED`.
30
+ When it does not, `login` says so.
31
+
32
+ ### From this repository
33
+
34
+ Before a release, or to try a change, build the command line in a clone of this repository and run its entry with
35
+ Node:
36
+
37
+ ```sh
38
+ yarn install
39
+ yarn --cwd packages/toolkit-types build
40
+ yarn --cwd packages/api build
41
+ yarn --cwd apps/cli build
42
+ node apps/cli/dist/index.js login --api-url http://localhost:3000/api
43
+ ```
44
+
45
+ ## Commands
46
+
47
+ Every command takes `--json`, `--api-url <url>` and `--help`. `ever-teams --help` lists the commands,
48
+ `ever-teams <command> --help` shows the options of one, and `ever-teams --version` the version.
49
+
50
+ ### login
51
+
52
+ ```sh
53
+ ever-teams login
54
+ ever-teams login --api-url https://teams.example.com/api
55
+ ever-teams login --token-stdin < token.txt
56
+ ```
57
+
58
+ Asks for a personal API token, checks it once, then keeps it with the address. With `--token-stdin` it reads the token
59
+ from the standard input, for a script. The token is never an argument, so it never lands in your shell history. A
60
+ token that is not a personal one (they start with `gzp_`) is refused. Over plain `http` to another machine than this
61
+ one, it warns that the token travels unencrypted.
62
+
63
+ ### logout
64
+
65
+ ```sh
66
+ ever-teams logout
67
+ ```
68
+
69
+ Removes the stored token. The token keeps working until you revoke it in **Settings > API tokens**.
70
+
71
+ ### status
72
+
73
+ ```sh
74
+ ever-teams status
75
+ ```
76
+
77
+ ```text
78
+ The timer is running since 09:12 (1h 05m) on Website, WEB-12 Fix the sign-in page.
79
+ Today: 3h 20m tracked.
80
+ ```
81
+
82
+ ### start
83
+
84
+ ```sh
85
+ ever-teams start
86
+ ever-teams start --project Website --task 12 --note "Review the pull request"
87
+ ```
88
+
89
+ `--project` takes a project's name (in any case) or its id, `--task` a task's number (`12`, `#12`, or `WEB-12` as the
90
+ app shows it) or its id, among your own. A task given alone brings its project. A timer already running stops first, as
91
+ in the apps. A name or a number that matches nothing, or more than one, is refused before the timer starts, with what
92
+ to give instead.
93
+
94
+ ### stop
95
+
96
+ ```sh
97
+ ever-teams stop
98
+ ```
99
+
100
+ ```text
101
+ Timer stopped at 10:17 after 1h 05m on Website, WEB-12 Fix the sign-in page.
102
+ ```
103
+
104
+ With no timer running, it says so and succeeds.
105
+
106
+ ### today
107
+
108
+ ```sh
109
+ ever-teams today
110
+ ```
111
+
112
+ ```text
113
+ Today (2026-11-18): 3h 00m tracked.
114
+ 08:30-10:00 1h 30m Website, WEB-12 Fix the sign-in page
115
+ 10:30-11:00 30m (no project)
116
+ 14:00-now 1h 00m Website: Call with the client
117
+ ```
118
+
119
+ Your entries started today, in the time zone of this computer. A running entry counts up to now.
120
+
121
+ ### log
122
+
123
+ ```sh
124
+ ever-teams log --from 09:00 --to 10:30 --project Website --note "Call with the client"
125
+ ever-teams log --date 2026-11-17 --from 14:00 --to 16:15 --task 12
126
+ ever-teams log --duration 45m --note "Code review"
127
+ ```
128
+
129
+ Adds time you worked without the timer: `--from` and `--to` on `--date` (today by default), or `--duration` (`1h30m`,
130
+ `2h`, `45m`) that starts at `--from`, ends at `--to`, or ends now. Times are in the time zone of this computer; a
131
+ time its clocks skip for daylight saving (02:30 on the day they move forward) is refused. `--project`, `--task` and `--note` work as for `start`. Your organization must allow manual time; an entry over a
132
+ running timer or a break is refused, and an entry it overlaps loses the time the new one covers, as in the web app.
133
+ The entry is billable as its project is set, as in the web app; `--billable` or `--not-billable` chooses instead.
134
+
135
+ ### export
136
+
137
+ ```sh
138
+ ever-teams export --from 2026-11-01 --to 2026-11-30 --format csv --output november.csv
139
+ ever-teams export --from 2026-11-18 --to 2026-11-18 --format json
140
+ ```
141
+
142
+ Writes your entries started from the first day to the last, both included, to the standard output, or to a file with
143
+ `--output` (replaced if it exists). With `--all`, it writes every entry your token may see: the team's, for a manager.
144
+
145
+ Both formats carry the same fields, and the CSV columns are named and ordered as the JSON keys: `id`, `startedAt`,
146
+ `stoppedAt` (empty while running), `durationSeconds`, `running`, `projectId`, `projectName`, `taskId`, `taskNumber`,
147
+ `taskTitle`, `note`, `logType`, `billable`, `memberId`, `memberName`. Times are ISO 8601 in UTC.
148
+
149
+ The CSV follows RFC 4180: a header row, a cell with a comma, a quote or a line end in quotes, quotes doubled, CRLF line
150
+ ends. A text that a spreadsheet would run as a formula (it starts with `=`, `+`, `-` or `@`) gets a leading `'`, so a
151
+ note never runs in the sheet that imports the export.
152
+
153
+ ### projects
154
+
155
+ ```sh
156
+ ever-teams projects
157
+ ```
158
+
159
+ ```text
160
+ Mobile app 2b6f1c3e-8a41-4f0e-9d2a-5c7e1b9a0f34
161
+ Website 7d1e2a90-3c5b-4e8f-a6d4-0b9c8e7f6a51
162
+ ```
163
+
164
+ Your projects, by name, with the id of each: `start` and `log` take either.
165
+
166
+ ## In a script
167
+
168
+ With `--json`, a command answers one JSON document on the standard output, and a failure answers one on the error
169
+ output:
170
+
171
+ ```json
172
+ {
173
+ "error": {
174
+ "code": "TOKEN_REFUSED",
175
+ "message": "Your token was refused: create a new one in Settings > API tokens, then run ever-teams login.",
176
+ "status": 401
177
+ }
178
+ }
179
+ ```
180
+
181
+ `status` is the HTTP status when the failure is an answer of the API. `export` without `--output` writes the CSV or the
182
+ JSON it was asked for, whatever `--json` says. `--help` with `--json` answers `{ "help": "..." }`, the text it prints
183
+ without `--json`.
184
+
185
+ | Exit code | Meaning |
186
+ | --------- | ------------------------------------------------------------------------------------- |
187
+ | `0` | Done (`stop` with no timer running included) |
188
+ | `1` | Refused or failed: by the API, by the network, or by the command line (not signed in) |
189
+ | `2` | Usage error: an unknown command or option, a value missing or not in its form |
190
+
191
+ A nightly job on Linux that writes yesterday's entries of the whole team, with the token from the job's secrets:
192
+
193
+ ```sh
194
+ export EVER_TEAMS_API_URL=https://teams.example.com/api
195
+ export EVER_TEAMS_TOKEN="$TEAMS_TOKEN"
196
+ day=$(date -d yesterday +%F)
197
+ ever-teams export --from "$day" --to "$day" --format csv --all --output "entries-$day.csv"
198
+ ```
199
+
200
+ ## Environment variables
201
+
202
+ | Variable | What it does |
203
+ | -------------------- | ------------------------------------------------------------------------------------------------- |
204
+ | `EVER_TEAMS_TOKEN` | A personal API token, used in place of the stored one. Nothing is written to disk. |
205
+ | `EVER_TEAMS_API_URL` | The API's address, ending with `/api`, used in place of the stored one. `--api-url` wins over it. |
206
+ | `XDG_CONFIG_HOME` | On Linux and macOS, the folder of the settings (`~/.config` when it is not set). |
207
+ | `APPDATA` | On Windows, the folder of the settings. |
208
+
209
+ ## Where the token is kept
210
+
211
+ `login` writes the address and the token to `config.json` in the folder `ever-teams` of your settings folder:
212
+
213
+ | System | File |
214
+ | --------------- | ---------------------------------------------------------------------------------- |
215
+ | Linux and macOS | `$XDG_CONFIG_HOME/ever-teams/config.json`, else `~/.config/ever-teams/config.json` |
216
+ | Windows | `%APPDATA%\ever-teams\config.json` |
217
+
218
+ On Linux and macOS the file has the mode `600`: only your account may read or write it. The stored token is sent only
219
+ to the address it was stored with: with another `--api-url` or `EVER_TEAMS_API_URL`, a command refuses and says to run
220
+ `ever-teams login` for that address, or to set `EVER_TEAMS_TOKEN`.
221
+
222
+ The command line never prints a token: not in a result, not in an error, not with `--json`, not when an answer of the
223
+ server repeats it.
224
+
225
+ ## When something goes wrong
226
+
227
+ Each failure is one sentence that says what to do next. The most common, by their `code` in JSON:
228
+
229
+ | Code | What happened | What to do |
230
+ | ----------------------- | ------------------------------------------------------------------------- | ---------------------------------------------------------------- |
231
+ | `NOT_SIGNED_IN` | No stored token and no `EVER_TEAMS_TOKEN` | Run `ever-teams login` |
232
+ | `TOKEN_REFUSED` | The token expired or was revoked | Create a new one in **Settings > API tokens**, then log in again |
233
+ | `PERSONAL_TOKENS_OFF` | The server does not accept personal API tokens | Its administrator sets `GAUZY_USER_API_TOKENS_ENABLED` |
234
+ | `OTHER_API` | The stored token belongs to another address | Run `ever-teams login --api-url <url>` |
235
+ | `MANUAL_TIME_REFUSED` | Your organization does not allow manual time, or your role may not add it | Ask an administrator, or use `start` and `stop` |
236
+ | `RUNNING_TIMER_OVERLAP` | The entry overlaps your running timer | Stop it, or pick another time |
237
+ | `NO_ANSWER` | No answer from the address | Check the network and the address |
238
+
239
+ ## License
240
+
241
+ MIT
package/dist/args.js ADDED
@@ -0,0 +1,54 @@
1
+ import { parseArgs } from 'node:util';
2
+ import { UsageError } from './refusals.js';
3
+ /** The options every command takes. */
4
+ export const COMMON_OPTIONS = {
5
+ json: { type: 'boolean' },
6
+ 'api-url': { type: 'string' },
7
+ help: { type: 'boolean', short: 'h' }
8
+ };
9
+ function checkValue(token, spec) {
10
+ if (spec.type === 'boolean') {
11
+ if (token.inlineValue) {
12
+ throw new UsageError(`${token.rawName} takes no value.`);
13
+ }
14
+ return;
15
+ }
16
+ if (token.value === undefined) {
17
+ throw new UsageError(`${token.rawName} needs a value.`);
18
+ }
19
+ // "--note --json" would take --json as the note.
20
+ const looksLikeOption = !token.inlineValue && token.value.startsWith('-');
21
+ if (looksLikeOption) {
22
+ throw new UsageError(`${token.rawName} needs a value. For a value that starts with -, write ${token.rawName}=${token.value}.`);
23
+ }
24
+ }
25
+ function checkToken(command, token, specs) {
26
+ if (token.kind === 'positional') {
27
+ throw new UsageError(`${command} takes options only, and ${token.value} is not one.`);
28
+ }
29
+ if (token.kind !== 'option') {
30
+ return;
31
+ }
32
+ const isKnown = Object.hasOwn(specs, token.name);
33
+ if (!isKnown) {
34
+ throw new UsageError(`${command} has no option ${token.rawName}.`);
35
+ }
36
+ checkValue(token, specs[token.name]);
37
+ }
38
+ /** The options after the command, each checked against the command's own and the common ones. */
39
+ export function parseOptions(command, args, own) {
40
+ const specs = { ...COMMON_OPTIONS, ...own };
41
+ const { values, tokens } = parseArgs({ args, options: specs, strict: false, allowPositionals: true, tokens: true });
42
+ for (const token of tokens) {
43
+ checkToken(command, token, specs);
44
+ }
45
+ return values;
46
+ }
47
+ export function textOption(values, name) {
48
+ const value = values[name];
49
+ if (typeof value === 'string') {
50
+ return value;
51
+ }
52
+ return undefined;
53
+ }
54
+ export const flagOption = (values, name) => values[name] === true;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,102 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+ import { flagOption, textOption } from '../args.js';
4
+ import { csvOf } from '../csv.js';
5
+ import { inStartOrder, recordOfEntry } from '../entries.js';
6
+ import { localDayOf } from '../past-range.js';
7
+ import { Refusal, UsageError } from '../refusals.js';
8
+ import { openSession } from '../session.js';
9
+ const FORMATS = new Set(['csv', 'json']);
10
+ function required(values, name, example) {
11
+ const value = textOption(values, name);
12
+ if (value === undefined) {
13
+ throw new UsageError(`Give --${name}, such as --${name} ${example}.`);
14
+ }
15
+ return value;
16
+ }
17
+ function checkPeriod(from, to) {
18
+ const start = localDayOf(from, '--from');
19
+ const end = localDayOf(to, '--to');
20
+ if (end.getTime() < start.getTime()) {
21
+ throw new UsageError('--to must not be before --from.');
22
+ }
23
+ }
24
+ function checkFormat(format) {
25
+ if (!FORMATS.has(format)) {
26
+ throw new UsageError(`--format takes csv or json, not ${format}.`);
27
+ }
28
+ }
29
+ function textOf(records, format) {
30
+ if (format === 'csv') {
31
+ return csvOf(records);
32
+ }
33
+ return `${JSON.stringify(records, null, 2)}\n`;
34
+ }
35
+ function writeExport(file, text) {
36
+ const target = path.resolve(file);
37
+ try {
38
+ fs.writeFileSync(target, text);
39
+ }
40
+ catch (error) {
41
+ const reason = error.code ?? 'an error';
42
+ const step = 'check that its folder exists and that you may write there';
43
+ throw new Refusal('CANNOT_WRITE', `${target} cannot be written (${reason}): ${step}.`);
44
+ }
45
+ return target;
46
+ }
47
+ function entriesWord(count) {
48
+ if (count === 1) {
49
+ return '1 entry';
50
+ }
51
+ return `${count} entries`;
52
+ }
53
+ async function exportEntries(context) {
54
+ const { values, io, output } = context;
55
+ const from = required(values, 'from', '2026-11-01');
56
+ const to = required(values, 'to', '2026-11-30');
57
+ const format = required(values, 'format', 'csv');
58
+ checkPeriod(from, to);
59
+ checkFormat(format);
60
+ const client = openSession(context);
61
+ const mine = !flagOption(values, 'all');
62
+ const listed = await client.timeEntries.list({ from, to, mine });
63
+ const now = io.now();
64
+ const records = inStartOrder(listed.map((entry) => recordOfEntry(entry, now)));
65
+ const text = textOf(records, format);
66
+ const file = textOption(values, 'output');
67
+ if (file === undefined) {
68
+ output.data(text);
69
+ return;
70
+ }
71
+ const written = writeExport(file, text);
72
+ output.result({ file: written, format, entries: records.length }, [
73
+ `Wrote ${entriesWord(records.length)} to ${written}.`
74
+ ]);
75
+ }
76
+ export const exportCommand = {
77
+ name: 'export',
78
+ summary: 'Write the time entries of a period as CSV or JSON',
79
+ usage: 'export --from <YYYY-MM-DD> --to <YYYY-MM-DD> --format csv|json [--output <file>] [--all]',
80
+ description: 'Writes your time entries started from the first day to the last, both included, in the time zone of this\n' +
81
+ 'computer: to the standard output, or to a file with --output (replaced if it exists). In CSV, a text\n' +
82
+ 'that a spreadsheet would run as a formula (it starts with =, +, -, @) gets a leading quote.',
83
+ options: {
84
+ from: { type: 'string' },
85
+ to: { type: 'string' },
86
+ format: { type: 'string' },
87
+ output: { type: 'string' },
88
+ all: { type: 'boolean' }
89
+ },
90
+ optionHelp: [
91
+ ['--from <YYYY-MM-DD>', 'The first day'],
92
+ ['--to <YYYY-MM-DD>', 'The last day'],
93
+ ['--format csv|json', 'CSV with a header row, or a JSON list'],
94
+ ['--output <file>', 'Write to this file instead of the standard output'],
95
+ ['--all', "Every member's entries your token may see (the team's, for a manager), not only yours"]
96
+ ],
97
+ examples: [
98
+ 'ever-teams export --from 2026-11-01 --to 2026-11-30 --format csv --output november.csv',
99
+ 'ever-teams export --from 2026-11-18 --to 2026-11-18 --format json'
100
+ ],
101
+ run: exportEntries
102
+ };
@@ -0,0 +1,21 @@
1
+ import { exportCommand } from './export.js';
2
+ import { logCommand } from './log.js';
3
+ import { loginCommand } from './login.js';
4
+ import { logoutCommand } from './logout.js';
5
+ import { projectsCommand } from './projects.js';
6
+ import { startCommand } from './start.js';
7
+ import { statusCommand } from './status.js';
8
+ import { stopCommand } from './stop.js';
9
+ import { todayCommand } from './today.js';
10
+ /** The commands, in the order the help lists them. */
11
+ export const COMMANDS = [
12
+ statusCommand,
13
+ startCommand,
14
+ stopCommand,
15
+ todayCommand,
16
+ logCommand,
17
+ exportCommand,
18
+ projectsCommand,
19
+ loginCommand,
20
+ logoutCommand
21
+ ];
@@ -0,0 +1,86 @@
1
+ import { flagOption, textOption } from '../args.js';
2
+ import { recordOfLog, workOf } from '../entries.js';
3
+ import { clockOf, dayOf, durationText } from '../format.js';
4
+ import { namesOf, workNamed } from '../lookup.js';
5
+ import { pastRangeOf } from '../past-range.js';
6
+ import { UsageError } from '../refusals.js';
7
+ import { openSession } from '../session.js';
8
+ /**
9
+ * The entry's billable choice: `--billable` or `--not-billable`. Without either, none is sent and the entry is
10
+ * billable as its project is set (ever-co/ever-teams#5571).
11
+ */
12
+ function billableChoiceOf(values) {
13
+ const billable = flagOption(values, 'billable');
14
+ const notBillable = flagOption(values, 'not-billable');
15
+ if (billable && notBillable) {
16
+ throw new UsageError('Give --billable or --not-billable, not both.');
17
+ }
18
+ if (billable) {
19
+ return true;
20
+ }
21
+ if (notBillable) {
22
+ return false;
23
+ }
24
+ return undefined;
25
+ }
26
+ async function log(context) {
27
+ const { values, io } = context;
28
+ const now = io.now();
29
+ const range = pastRangeOf(values, now);
30
+ const isBillable = billableChoiceOf(values);
31
+ const client = openSession(context);
32
+ const work = await workNamed(client, values);
33
+ const note = textOption(values, 'note') || undefined;
34
+ const created = await client.timeEntries.create({
35
+ startedAt: range.start,
36
+ stoppedAt: range.end,
37
+ projectId: work.projectId,
38
+ taskId: work.taskId,
39
+ description: note,
40
+ isBillable
41
+ });
42
+ const names = await namesOf(client, created, work);
43
+ const entry = recordOfLog(created, names, now);
44
+ const when = `on ${dayOf(range.start)}, from ${clockOf(range.start)} to ${clockOf(range.end)}`;
45
+ context.output.result({ added: true, entry }, [
46
+ `Added ${durationText(entry.durationSeconds)} ${when}${workOf(entry)}.`
47
+ ]);
48
+ }
49
+ export const logCommand = {
50
+ name: 'log',
51
+ summary: 'Add a past time entry, where your organization allows manual time',
52
+ usage: 'log --from <HH:MM> --to <HH:MM> [--date <YYYY-MM-DD>] [options]\n' +
53
+ ' ever-teams log --duration <1h30m> [--from <HH:MM> | --to <HH:MM>] [--date <YYYY-MM-DD>] [options]',
54
+ description: 'Adds time you worked without the timer: from a time to another on a day (today by default), or for a\n' +
55
+ 'duration that starts at --from, ends at --to, or ends now. Times are in the time zone of this computer.\n' +
56
+ 'Your organization must allow manual time; an entry over a running timer or a break is refused. The entry is\n' +
57
+ 'billable as its project is set, unless you give --billable or --not-billable.',
58
+ options: {
59
+ from: { type: 'string' },
60
+ to: { type: 'string' },
61
+ date: { type: 'string' },
62
+ duration: { type: 'string' },
63
+ project: { type: 'string' },
64
+ task: { type: 'string' },
65
+ note: { type: 'string' },
66
+ billable: { type: 'boolean' },
67
+ 'not-billable': { type: 'boolean' }
68
+ },
69
+ optionHelp: [
70
+ ['--from <HH:MM>', 'When the entry starts'],
71
+ ['--to <HH:MM>', 'When it ends'],
72
+ ['--date <YYYY-MM-DD>', 'The day of --from and --to; today by default'],
73
+ ['--duration <1h30m>', 'How long it lasts: 1h30m, 2h or 45m'],
74
+ ['--project <name or id>', 'One of your projects (ever-teams projects lists them)'],
75
+ ['--task <number or id>', 'One of your tasks: 12, #12, its number as the app shows it, or its id'],
76
+ ['--note <text>', 'What you worked on'],
77
+ ['--billable', 'Bill the entry, whatever its project says'],
78
+ ['--not-billable', 'Do not bill it, whatever its project says']
79
+ ],
80
+ examples: [
81
+ 'ever-teams log --from 09:00 --to 10:30 --project Website --note "Call with the client"',
82
+ 'ever-teams log --date 2026-11-17 --from 14:00 --to 16:15 --task 12',
83
+ 'ever-teams log --duration 45m --note "Code review"'
84
+ ],
85
+ run: log
86
+ };
@@ -0,0 +1,76 @@
1
+ import { flagOption } from '../args.js';
2
+ import { readLogin, writeLogin } from '../config.js';
3
+ import { readHidden, readPiped } from '../prompt.js';
4
+ import { Refusal, UsageError } from '../refusals.js';
5
+ import { apiUrlOf, clientFor, isUnencrypted } from '../session.js';
6
+ // Gauzy's personal API tokens start with it: a login keeps only a token that lasts.
7
+ const PERSONAL_TOKEN_PREFIX = 'gzp_';
8
+ const QUESTION = 'Personal API token (hidden while you type or paste it): ';
9
+ async function tokenGiven(context) {
10
+ const input = context.io.stdin;
11
+ if (flagOption(context.values, 'token-stdin')) {
12
+ return readPiped(input);
13
+ }
14
+ const canPrompt = input.isTTY === true && typeof input.setRawMode === 'function';
15
+ if (!canPrompt) {
16
+ throw new UsageError('There is no terminal to type the token in: pipe it in with --token-stdin.');
17
+ }
18
+ return readHidden(input, (text) => context.io.writeErr(text), QUESTION);
19
+ }
20
+ // A settings file that cannot be read is the one login replaces: it gives no address, and is no reason to refuse.
21
+ function storedLogin(context) {
22
+ try {
23
+ return readLogin(context.io);
24
+ }
25
+ catch (error) {
26
+ const isDamaged = error instanceof Refusal && error.code === 'SETTINGS_DAMAGED';
27
+ if (isDamaged) {
28
+ return null;
29
+ }
30
+ throw error;
31
+ }
32
+ }
33
+ function checkToken(token) {
34
+ if (!token) {
35
+ throw new UsageError('No token was given.');
36
+ }
37
+ if (!token.startsWith(PERSONAL_TOKEN_PREFIX)) {
38
+ throw new UsageError('This is not a personal API token, which starts with gzp_: create one in Settings > API tokens.');
39
+ }
40
+ }
41
+ async function login(context) {
42
+ const { io, output } = context;
43
+ const apiUrl = apiUrlOf(context, storedLogin(context));
44
+ const token = await tokenGiven(context);
45
+ output.hide(token);
46
+ checkToken(token);
47
+ if (isUnencrypted(apiUrl)) {
48
+ output.note(`Warning: ${apiUrl} is not https, so the token travels unencrypted.`);
49
+ }
50
+ const client = clientFor(context, apiUrl, token, 'typed');
51
+ await client.timer.status();
52
+ const file = writeLogin(io, { apiUrl, token });
53
+ output.result({ signedIn: true, apiUrl, settingsFile: file }, [
54
+ `Signed in to ${apiUrl}. The token is kept in ${file}.`
55
+ ]);
56
+ if (io.env.EVER_TEAMS_TOKEN) {
57
+ output.note('EVER_TEAMS_TOKEN is set in this shell: the command line uses it in place of the stored token.');
58
+ }
59
+ }
60
+ export const loginCommand = {
61
+ name: 'login',
62
+ summary: 'Sign in with a personal API token, checked once, then kept',
63
+ usage: 'login [--token-stdin] [--api-url <url>]',
64
+ description: 'Asks for a personal API token (create one in Settings > API tokens of the web app), checks it once\n' +
65
+ 'with the server, then keeps it with the address in your settings folder (on Linux and macOS in a file\n' +
66
+ 'of mode 600, which other accounts may not read). The token is never an argument, so it never lands in\n' +
67
+ 'your shell history.',
68
+ options: { 'token-stdin': { type: 'boolean' } },
69
+ optionHelp: [['--token-stdin', 'Read the token from the standard input instead of asking for it']],
70
+ examples: [
71
+ 'ever-teams login',
72
+ 'ever-teams login --api-url https://teams.example.com/api',
73
+ 'ever-teams login --token-stdin < token.txt'
74
+ ],
75
+ run: login
76
+ };
@@ -0,0 +1,24 @@
1
+ import { removeLogin } from '../config.js';
2
+ async function logout(context) {
3
+ const { io, output } = context;
4
+ const removed = removeLogin(io);
5
+ let line = 'You were not signed in: there is no stored token.';
6
+ if (removed) {
7
+ line =
8
+ 'Signed out: the stored token is removed. It keeps working until you revoke it in Settings > API tokens.';
9
+ }
10
+ output.result({ signedOut: removed }, [line]);
11
+ if (io.env.EVER_TEAMS_TOKEN) {
12
+ output.note('EVER_TEAMS_TOKEN is still set in this shell, and the command line still uses it.');
13
+ }
14
+ }
15
+ export const logoutCommand = {
16
+ name: 'logout',
17
+ summary: 'Remove the stored token',
18
+ usage: 'logout',
19
+ description: 'Removes the token login stored. To make the token stop working, revoke it in Settings > API tokens.',
20
+ options: {},
21
+ optionHelp: [],
22
+ examples: ['ever-teams logout'],
23
+ run: logout
24
+ };
@@ -0,0 +1,26 @@
1
+ import { openSession } from '../session.js';
2
+ const byName = (a, b) => a.name.localeCompare(b.name);
3
+ function linesOf(projects) {
4
+ if (projects.length === 0) {
5
+ return ['You are a member of no project.'];
6
+ }
7
+ const width = Math.max(...projects.map((project) => project.name.length));
8
+ return projects.map((project) => `${project.name.padEnd(width)} ${project.id}`);
9
+ }
10
+ async function projects(context) {
11
+ const client = openSession(context);
12
+ const listed = await client.projects.list();
13
+ const named = listed.map(({ id, name }) => ({ id, name }));
14
+ const sorted = named.sort(byName);
15
+ context.output.result({ projects: sorted }, linesOf(sorted));
16
+ }
17
+ export const projectsCommand = {
18
+ name: 'projects',
19
+ summary: 'List your projects, with the id of each',
20
+ usage: 'projects',
21
+ description: 'Lists the projects you are a member of, by name, with the id of each: start and log take either.',
22
+ options: {},
23
+ optionHelp: [],
24
+ examples: ['ever-teams projects', 'ever-teams projects --json'],
25
+ run: projects
26
+ };