@wat-toolbox/wat 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 +62 -0
- package/dist/cli/commands/availability.d.ts +10 -0
- package/dist/cli/commands/availability.d.ts.map +1 -0
- package/dist/cli/commands/availability.js +83 -0
- package/dist/cli/commands/availability.js.map +1 -0
- package/dist/cli/commands/bookings.d.ts +12 -0
- package/dist/cli/commands/bookings.d.ts.map +1 -0
- package/dist/cli/commands/bookings.js +195 -0
- package/dist/cli/commands/bookings.js.map +1 -0
- package/dist/cli/commands/config.d.ts +7 -0
- package/dist/cli/commands/config.d.ts.map +1 -0
- package/dist/cli/commands/config.js +59 -0
- package/dist/cli/commands/config.js.map +1 -0
- package/dist/cli/commands/login.d.ts +11 -0
- package/dist/cli/commands/login.d.ts.map +1 -0
- package/dist/cli/commands/login.js +127 -0
- package/dist/cli/commands/login.js.map +1 -0
- package/dist/cli/commands/logout.d.ts +8 -0
- package/dist/cli/commands/logout.d.ts.map +1 -0
- package/dist/cli/commands/logout.js +38 -0
- package/dist/cli/commands/logout.js.map +1 -0
- package/dist/cli/commands/rooms.d.ts +22 -0
- package/dist/cli/commands/rooms.d.ts.map +1 -0
- package/dist/cli/commands/rooms.js +76 -0
- package/dist/cli/commands/rooms.js.map +1 -0
- package/dist/cli/commands/whoami.d.ts +6 -0
- package/dist/cli/commands/whoami.d.ts.map +1 -0
- package/dist/cli/commands/whoami.js +37 -0
- package/dist/cli/commands/whoami.js.map +1 -0
- package/dist/cli/index.d.ts +22 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +61 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/utils/output.d.ts +28 -0
- package/dist/cli/utils/output.d.ts.map +1 -0
- package/dist/cli/utils/output.js +40 -0
- package/dist/cli/utils/output.js.map +1 -0
- package/dist/cli/utils/require-key.d.ts +6 -0
- package/dist/cli/utils/require-key.d.ts.map +1 -0
- package/dist/cli/utils/require-key.js +18 -0
- package/dist/cli/utils/require-key.js.map +1 -0
- package/dist/utils/api-client.d.ts +35 -0
- package/dist/utils/api-client.d.ts.map +1 -0
- package/dist/utils/api-client.js +98 -0
- package/dist/utils/api-client.js.map +1 -0
- package/dist/utils/auth-flow-client.d.ts +60 -0
- package/dist/utils/auth-flow-client.d.ts.map +1 -0
- package/dist/utils/auth-flow-client.js +28 -0
- package/dist/utils/auth-flow-client.js.map +1 -0
- package/dist/utils/config.d.ts +95 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +246 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/rooms-client.d.ts +70 -0
- package/dist/utils/rooms-client.d.ts.map +1 -0
- package/dist/utils/rooms-client.js +59 -0
- package/dist/utils/rooms-client.js.map +1 -0
- package/dist/utils/time.d.ts +37 -0
- package/dist/utils/time.d.ts.map +1 -0
- package/dist/utils/time.js +130 -0
- package/dist/utils/time.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Codika
|
|
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
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# wat — WAT Rooms CLI
|
|
2
|
+
|
|
3
|
+
Book WAT meeting rooms from the terminal. The CLI drives the **same** public API the web app uses (`/api/rooms`, `/api/availability`, `/api/bookings`), authenticated with a minted API key sent as a Bearer token. Package `@wat-toolbox/wat`, command `wat`.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @wat-toolbox/wat
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick start
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
wat login # email-OTP → mints + stores an API key
|
|
15
|
+
wat rooms list
|
|
16
|
+
wat availability --room "Room A" --from 2026-06-09 --to 2026-06-10
|
|
17
|
+
wat bookings list --mine
|
|
18
|
+
wat bookings create --room "Room A" --start "2026-06-09T10:00" --end "2026-06-09T11:00" --title "Sync"
|
|
19
|
+
wat bookings cancel <id>
|
|
20
|
+
wat whoami
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Environment targeting
|
|
24
|
+
|
|
25
|
+
`--env` selects the deployment. Precedence (highest first): `--api-url` flag › `WAT_CLI_API_BASE_URL` › profile `baseUrl` › `--env` / `WAT_CLI_ENV` › prod default.
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
wat --env dev rooms list # → https://wat-app-git-stag-codika.vercel.app (development data)
|
|
29
|
+
wat --env prod rooms list # → https://wat-app.vercel.app (default)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Time interpretation
|
|
33
|
+
|
|
34
|
+
A bare `--start "2026-06-09T10:00"` is read as **Europe/Brussels** wall-clock (matching the web UI) and converted to UTC for the API. Override the zone with `--tz <IANA>`. A value carrying an explicit offset (`2026-06-09T10:00+02:00`) or `Z` is honored as-is. Times are printed back in the same zone the CLI accepted, so what you type and what you see never disagree.
|
|
35
|
+
|
|
36
|
+
## Auth & config
|
|
37
|
+
|
|
38
|
+
`wat login` runs an email-OTP flow; on a first enrollment you also pass the WAT signup code (`--signup-code`, or interactively). The minted **API key** is stored in `~/.config/wat/config.json` (mode 0600) and sent as `Authorization: Bearer <key>`. The key carries your member role: member keys get the member surface, admin keys can drive admin actions.
|
|
39
|
+
|
|
40
|
+
- `wat config show` — profiles + resolved targeting.
|
|
41
|
+
- `wat logout` — remove the local key (active profile, or `--all`). Revoke a key everywhere from the web app's settings page.
|
|
42
|
+
|
|
43
|
+
Override the key per-call with `--api-key <key>` or `WAT_CLI_API_KEY`.
|
|
44
|
+
|
|
45
|
+
## Output
|
|
46
|
+
|
|
47
|
+
Every command supports `--json` for machine consumption (the format the `wat-plugin` skills parse):
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{ "success": true, "data": { ... } }
|
|
51
|
+
{ "success": false, "error": { "code": "...", "message": "...", "nextAction": "..." } }
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Develop
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install
|
|
58
|
+
npm run build # tsc → dist/
|
|
59
|
+
npm test # vitest (config precedence + Brussels time conversion)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Scaffolded from `codika-cli-template`, mirroring the codika-meet CLI's `--env` + profile model.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wat availability --room <room> --from <when> --to <when> [--tz <IANA>]`
|
|
3
|
+
*
|
|
4
|
+
* Free/busy for a room over a window. Bare `--from`/`--to` are read as
|
|
5
|
+
* Europe/Brussels wall-clock (or `--tz`); a value with an offset is honored
|
|
6
|
+
* as-is. Free ranges are printed back in the same zone.
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from 'commander';
|
|
9
|
+
export declare const availabilityCommand: Command;
|
|
10
|
+
//# sourceMappingURL=availability.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"availability.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/availability.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAapC,eAAO,MAAM,mBAAmB,SA6E7B,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wat availability --room <room> --from <when> --to <when> [--tz <IANA>]`
|
|
3
|
+
*
|
|
4
|
+
* Free/busy for a room over a window. Bare `--from`/`--to` are read as
|
|
5
|
+
* Europe/Brussels wall-clock (or `--tz`); a value with an offset is honored
|
|
6
|
+
* as-is. Free ranges are printed back in the same zone.
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from 'commander';
|
|
9
|
+
import { getAvailability } from '../../utils/rooms-client.js';
|
|
10
|
+
import { resolveRoom } from './rooms.js';
|
|
11
|
+
import { parseDateTimeArg, formatInZone, DEFAULT_TZ } from '../../utils/time.js';
|
|
12
|
+
import { bold, dim, emitJsonError, emitJsonSuccess, failHuman, green } from '../utils/output.js';
|
|
13
|
+
import { requireApiKey } from '../utils/require-key.js';
|
|
14
|
+
import { resolveBaseUrl } from '../../utils/config.js';
|
|
15
|
+
export const availabilityCommand = new Command('availability')
|
|
16
|
+
.description('Show free ranges for a room over a window')
|
|
17
|
+
.requiredOption('--room <name|id>', 'Room name or id')
|
|
18
|
+
.requiredOption('--from <when>', 'Window start (Brussels wall-clock, or ISO with offset)')
|
|
19
|
+
.requiredOption('--to <when>', 'Window end')
|
|
20
|
+
.option('--tz <iana>', `Interpret bare times in this zone (default ${DEFAULT_TZ})`)
|
|
21
|
+
.option('--api-key <key>', 'API key (overrides the saved profile)')
|
|
22
|
+
.option('--api-url <url>', 'Override the API base URL')
|
|
23
|
+
.option('--json', 'Output as JSON')
|
|
24
|
+
.action(async (options) => {
|
|
25
|
+
const apiKey = requireApiKey(options.apiKey, options.json);
|
|
26
|
+
const tz = options.tz || DEFAULT_TZ;
|
|
27
|
+
let fromUtc;
|
|
28
|
+
let toUtc;
|
|
29
|
+
try {
|
|
30
|
+
fromUtc = parseDateTimeArg(options.from, tz).date;
|
|
31
|
+
toUtc = parseDateTimeArg(options.to, tz).date;
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
const err = { code: 'INVALID_TIME', message: e instanceof Error ? e.message : String(e) };
|
|
35
|
+
if (options.json)
|
|
36
|
+
emitJsonError(err);
|
|
37
|
+
else
|
|
38
|
+
failHuman(err);
|
|
39
|
+
process.exit(1);
|
|
40
|
+
}
|
|
41
|
+
const room = await resolveRoom(apiKey, options.apiUrl, options.room);
|
|
42
|
+
if (!room.ok) {
|
|
43
|
+
if (options.json)
|
|
44
|
+
emitJsonError(room.error);
|
|
45
|
+
else
|
|
46
|
+
failHuman(room.error);
|
|
47
|
+
process.exit(1);
|
|
48
|
+
}
|
|
49
|
+
const result = await getAvailability({
|
|
50
|
+
apiKey,
|
|
51
|
+
baseUrl: options.apiUrl,
|
|
52
|
+
roomId: room.room.id,
|
|
53
|
+
from: fromUtc.toISOString(),
|
|
54
|
+
to: toUtc.toISOString()
|
|
55
|
+
});
|
|
56
|
+
if (!result.success) {
|
|
57
|
+
if (options.json)
|
|
58
|
+
emitJsonError(result.error, result.status);
|
|
59
|
+
else
|
|
60
|
+
failHuman(result.error);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
}
|
|
63
|
+
const free = result.data.free ?? [];
|
|
64
|
+
if (options.json) {
|
|
65
|
+
emitJsonSuccess({ room: { id: room.room.id, name: room.room.name }, tz, free, busy: result.data.busy });
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
console.log('');
|
|
69
|
+
console.log(`${bold(room.room.name)} ${dim('— free ranges (' + tz + ')')}`);
|
|
70
|
+
console.log('');
|
|
71
|
+
if (free.length === 0) {
|
|
72
|
+
console.log(dim(' Fully booked over this window.'));
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
for (const r of free) {
|
|
76
|
+
console.log(` ${green('●')} ${formatInZone(new Date(r.start), tz)} → ${formatInZone(new Date(r.end), tz)}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
console.log('');
|
|
80
|
+
console.log(dim(` base: ${resolveBaseUrl(options.apiUrl)}`));
|
|
81
|
+
console.log('');
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=availability.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"availability.js","sourceRoot":"","sources":["../../../src/cli/commands/availability.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACjF,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,aAAa,EAAE,eAAe,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACjG,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAOvD,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,OAAO,CAAC,cAAc,CAAC;KAC3D,WAAW,CAAC,2CAA2C,CAAC;KACxD,cAAc,CAAC,kBAAkB,EAAE,iBAAiB,CAAC;KACrD,cAAc,CAAC,eAAe,EAAE,wDAAw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AE,CAAC,CAAC;IAC5E,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC,CAAC;IACvD,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;YACrB,OAAO,CAAC,GAAG,CACT,KAAK,KAAK,CAAC,GAAG,CAAC,IAAI,YAAY,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,QAAQ,YAAY,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE,CAClG,CAAC;QACJ,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAChB,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,cAAc,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC9D,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC,CACF,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wat bookings list [--mine] [--room <room>] [--from <when>] [--to <when>]`
|
|
3
|
+
* `wat bookings create --room <room> --start <when> --end <when> [--title <t>] [--tz <iana>]`
|
|
4
|
+
* `wat bookings cancel <id>`
|
|
5
|
+
*
|
|
6
|
+
* Bookings go through the SAME /api/bookings the web UI uses (Bearer-gated). Bare
|
|
7
|
+
* `--start`/`--end` are read as Europe/Brussels wall-clock (or `--tz`) and
|
|
8
|
+
* converted to UTC for the API; times are printed back in the same zone.
|
|
9
|
+
*/
|
|
10
|
+
import { Command } from 'commander';
|
|
11
|
+
export declare const bookingsCommand: Command;
|
|
12
|
+
//# sourceMappingURL=bookings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bookings.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/bookings.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,eAAO,MAAM,eAAe,SAAuD,CAAC"}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wat bookings list [--mine] [--room <room>] [--from <when>] [--to <when>]`
|
|
3
|
+
* `wat bookings create --room <room> --start <when> --end <when> [--title <t>] [--tz <iana>]`
|
|
4
|
+
* `wat bookings cancel <id>`
|
|
5
|
+
*
|
|
6
|
+
* Bookings go through the SAME /api/bookings the web UI uses (Bearer-gated). Bare
|
|
7
|
+
* `--start`/`--end` are read as Europe/Brussels wall-clock (or `--tz`) and
|
|
8
|
+
* converted to UTC for the API; times are printed back in the same zone.
|
|
9
|
+
*/
|
|
10
|
+
import { Command } from 'commander';
|
|
11
|
+
import { listBookings, createBooking, cancelBooking } from '../../utils/rooms-client.js';
|
|
12
|
+
import { resolveRoom } from './rooms.js';
|
|
13
|
+
import { parseDateTimeArg, formatInZone, DEFAULT_TZ } from '../../utils/time.js';
|
|
14
|
+
import { bold, cyan, dim, emitJsonError, emitJsonSuccess, failHuman, green, CHECK } from '../utils/output.js';
|
|
15
|
+
import { requireApiKey } from '../utils/require-key.js';
|
|
16
|
+
export const bookingsCommand = new Command('bookings').description('Room bookings');
|
|
17
|
+
// ── list ─────────────────────────────────────────────────
|
|
18
|
+
bookingsCommand
|
|
19
|
+
.command('list')
|
|
20
|
+
.description('List bookings (optionally just your own)')
|
|
21
|
+
.option('--mine', 'Only your own bookings')
|
|
22
|
+
.option('--room <name|id>', 'Filter to one room')
|
|
23
|
+
.option('--from <when>', 'Only bookings ending after this instant')
|
|
24
|
+
.option('--to <when>', 'Only bookings starting before this instant')
|
|
25
|
+
.option('--tz <iana>', `Interpret bare times + display in this zone (default ${DEFAULT_TZ})`)
|
|
26
|
+
.option('--api-key <key>', 'API key (overrides the saved profile)')
|
|
27
|
+
.option('--api-url <url>', 'Override the API base URL')
|
|
28
|
+
.option('--json', 'Output as JSON')
|
|
29
|
+
.action(async (options) => {
|
|
30
|
+
const apiKey = requireApiKey(options.apiKey, options.json);
|
|
31
|
+
const tz = options.tz || DEFAULT_TZ;
|
|
32
|
+
let roomId;
|
|
33
|
+
if (options.room) {
|
|
34
|
+
const room = await resolveRoom(apiKey, options.apiUrl, options.room);
|
|
35
|
+
if (!room.ok) {
|
|
36
|
+
if (options.json)
|
|
37
|
+
emitJsonError(room.error);
|
|
38
|
+
else
|
|
39
|
+
failHuman(room.error);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
roomId = room.room.id;
|
|
43
|
+
}
|
|
44
|
+
let from;
|
|
45
|
+
let to;
|
|
46
|
+
try {
|
|
47
|
+
if (options.from)
|
|
48
|
+
from = parseDateTimeArg(options.from, tz).date.toISOString();
|
|
49
|
+
if (options.to)
|
|
50
|
+
to = parseDateTimeArg(options.to, tz).date.toISOString();
|
|
51
|
+
}
|
|
52
|
+
catch (e) {
|
|
53
|
+
const err = { code: 'INVALID_TIME', message: e instanceof Error ? e.message : String(e) };
|
|
54
|
+
if (options.json)
|
|
55
|
+
emitJsonError(err);
|
|
56
|
+
else
|
|
57
|
+
failHuman(err);
|
|
58
|
+
process.exit(1);
|
|
59
|
+
}
|
|
60
|
+
const result = await listBookings({
|
|
61
|
+
apiKey,
|
|
62
|
+
baseUrl: options.apiUrl,
|
|
63
|
+
roomId,
|
|
64
|
+
from,
|
|
65
|
+
to,
|
|
66
|
+
mine: options.mine
|
|
67
|
+
});
|
|
68
|
+
if (!result.success) {
|
|
69
|
+
if (options.json)
|
|
70
|
+
emitJsonError(result.error, result.status);
|
|
71
|
+
else
|
|
72
|
+
failHuman(result.error);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
const bookings = result.data.bookings ?? [];
|
|
76
|
+
if (options.json) {
|
|
77
|
+
emitJsonSuccess({ tz, bookings });
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (bookings.length === 0) {
|
|
81
|
+
console.log(dim('No bookings.'));
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
console.log('');
|
|
85
|
+
for (const b of bookings) {
|
|
86
|
+
printBookingLine(b, tz);
|
|
87
|
+
}
|
|
88
|
+
console.log('');
|
|
89
|
+
});
|
|
90
|
+
function printBookingLine(b, tz) {
|
|
91
|
+
const when = `${formatInZone(new Date(b.starts_at), tz)} → ${formatInZone(new Date(b.ends_at), tz)}`;
|
|
92
|
+
const who = b.is_maintenance
|
|
93
|
+
? dim('Unavailable (maintenance)')
|
|
94
|
+
: b.is_mine
|
|
95
|
+
? green('you')
|
|
96
|
+
: (b.booker_name ?? dim('someone'));
|
|
97
|
+
const label = b.title ? bold(b.title) : dim('(no title)');
|
|
98
|
+
const status = b.status === 'cancelled' ? dim(' [cancelled]') : '';
|
|
99
|
+
console.log(`${label}${status}`);
|
|
100
|
+
console.log(` ${when}`);
|
|
101
|
+
console.log(` ${dim('by ')}${who} ${dim('· id: ' + b.id)}`);
|
|
102
|
+
}
|
|
103
|
+
// ── create ───────────────────────────────────────────────
|
|
104
|
+
bookingsCommand
|
|
105
|
+
.command('create')
|
|
106
|
+
.description('Create a booking')
|
|
107
|
+
.requiredOption('--room <name|id>', 'Room name or id')
|
|
108
|
+
.requiredOption('--start <when>', 'Start (Brussels wall-clock, or ISO with offset)')
|
|
109
|
+
.requiredOption('--end <when>', 'End')
|
|
110
|
+
.option('--title <title>', 'Booking title (only you + admins see it)')
|
|
111
|
+
.option('--tz <iana>', `Interpret bare times in this zone (default ${DEFAULT_TZ})`)
|
|
112
|
+
.option('--api-key <key>', 'API key (overrides the saved profile)')
|
|
113
|
+
.option('--api-url <url>', 'Override the API base URL')
|
|
114
|
+
.option('--json', 'Output as JSON')
|
|
115
|
+
.action(async (options) => {
|
|
116
|
+
const apiKey = requireApiKey(options.apiKey, options.json);
|
|
117
|
+
const tz = options.tz || DEFAULT_TZ;
|
|
118
|
+
let startUtc;
|
|
119
|
+
let endUtc;
|
|
120
|
+
try {
|
|
121
|
+
startUtc = parseDateTimeArg(options.start, tz).date;
|
|
122
|
+
endUtc = parseDateTimeArg(options.end, tz).date;
|
|
123
|
+
}
|
|
124
|
+
catch (e) {
|
|
125
|
+
const err = { code: 'INVALID_TIME', message: e instanceof Error ? e.message : String(e) };
|
|
126
|
+
if (options.json)
|
|
127
|
+
emitJsonError(err);
|
|
128
|
+
else
|
|
129
|
+
failHuman(err);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
const room = await resolveRoom(apiKey, options.apiUrl, options.room);
|
|
133
|
+
if (!room.ok) {
|
|
134
|
+
if (options.json)
|
|
135
|
+
emitJsonError(room.error);
|
|
136
|
+
else
|
|
137
|
+
failHuman(room.error);
|
|
138
|
+
process.exit(1);
|
|
139
|
+
}
|
|
140
|
+
const result = await createBooking({
|
|
141
|
+
apiKey,
|
|
142
|
+
baseUrl: options.apiUrl,
|
|
143
|
+
roomId: room.room.id,
|
|
144
|
+
startsAt: startUtc.toISOString(),
|
|
145
|
+
endsAt: endUtc.toISOString(),
|
|
146
|
+
...(options.title ? { title: options.title } : {})
|
|
147
|
+
});
|
|
148
|
+
if (!result.success) {
|
|
149
|
+
if (options.json)
|
|
150
|
+
emitJsonError(result.error, result.status);
|
|
151
|
+
else
|
|
152
|
+
failHuman(result.error);
|
|
153
|
+
process.exit(1);
|
|
154
|
+
}
|
|
155
|
+
if (options.json) {
|
|
156
|
+
emitJsonSuccess({
|
|
157
|
+
booking: result.data.booking,
|
|
158
|
+
room: { id: room.room.id, name: room.room.name },
|
|
159
|
+
tz,
|
|
160
|
+
startsAt: startUtc.toISOString(),
|
|
161
|
+
endsAt: endUtc.toISOString()
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
console.log('');
|
|
166
|
+
console.log(`${CHECK} ${green('Booked')} ${bold(room.room.name)}`);
|
|
167
|
+
console.log(` ${formatInZone(startUtc, tz)} → ${formatInZone(endUtc, tz)}`);
|
|
168
|
+
console.log(` ${dim('id: ' + result.data.booking.id)}`);
|
|
169
|
+
console.log('');
|
|
170
|
+
});
|
|
171
|
+
// ── cancel ───────────────────────────────────────────────
|
|
172
|
+
bookingsCommand
|
|
173
|
+
.command('cancel')
|
|
174
|
+
.description('Cancel a booking by id')
|
|
175
|
+
.argument('<id>', 'Booking id')
|
|
176
|
+
.option('--api-key <key>', 'API key (overrides the saved profile)')
|
|
177
|
+
.option('--api-url <url>', 'Override the API base URL')
|
|
178
|
+
.option('--json', 'Output as JSON')
|
|
179
|
+
.action(async (id, options) => {
|
|
180
|
+
const apiKey = requireApiKey(options.apiKey, options.json);
|
|
181
|
+
const result = await cancelBooking({ apiKey, baseUrl: options.apiUrl, id });
|
|
182
|
+
if (!result.success) {
|
|
183
|
+
if (options.json)
|
|
184
|
+
emitJsonError(result.error, result.status);
|
|
185
|
+
else
|
|
186
|
+
failHuman(result.error);
|
|
187
|
+
process.exit(1);
|
|
188
|
+
}
|
|
189
|
+
if (options.json) {
|
|
190
|
+
emitJsonSuccess({ cancelled: id });
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
console.log(`${CHECK} ${green('Cancelled')} ${cyan(id)}`);
|
|
194
|
+
});
|
|
195
|
+
//# sourceMappingURL=bookings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bookings.js","sourceRoot":"","sources":["../../../src/cli/commands/bookings.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAgB,MAAM,6BAA6B,CAAC;AACvG,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,YAAY,E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C,CACF,CAAC;AAEJ,4DAA4D;AAC5D,eAAe;KACZ,OAAO,CAAC,QAAQ,CAAC;KACjB,WAAW,CAAC,wBAAwB,CAAC;KACrC,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;KAC9B,MAAM,CAAC,iBAAiB,EAAE,uCAAuC,CAAC;KAClE,MAAM,CAAC,iBAAiB,EAAE,2BAA2B,CAAC;KACtD,MAAM,CAAC,QAAQ,EAAE,gBAAgB,CAAC;KAClC,MAAM,CAAC,KAAK,EAAE,EAAU,EAAE,OAA6D,EAAE,EAAE;IAC1F,MAAM,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3D,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC;IAE5E,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;QACpB,IAAI,OAAO,CAAC,IAAI;YAAE,aAAa,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;;YACxD,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACjB,eAAe,CAAC,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC;QACnC,OAAO;IACT,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,IAAI,KAAK,CAAC,WAAW,CAAC,IAAI,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAC5D,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wat config show` — show profiles + the resolved base URL / key source.
|
|
3
|
+
* `wat config clear` — remove the entire local config file.
|
|
4
|
+
*/
|
|
5
|
+
import { Command } from 'commander';
|
|
6
|
+
export declare const configCommand: Command;
|
|
7
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAYpC,eAAO,MAAM,aAAa,SAA+D,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wat config show` — show profiles + the resolved base URL / key source.
|
|
3
|
+
* `wat config clear` — remove the entire local config file.
|
|
4
|
+
*/
|
|
5
|
+
import { Command } from 'commander';
|
|
6
|
+
import { clearConfig, describeApiKeySource, describeBaseUrlSource, getConfigPath, listProfiles, maskApiKey, resolveBaseUrl } from '../../utils/config.js';
|
|
7
|
+
import { CHECK, cyan, dim, emitJsonSuccess, green } from '../utils/output.js';
|
|
8
|
+
export const configCommand = new Command('config').description('Manage local CLI config');
|
|
9
|
+
configCommand
|
|
10
|
+
.command('show')
|
|
11
|
+
.description('Show profiles and resolved targeting')
|
|
12
|
+
.option('--json', 'Output as JSON')
|
|
13
|
+
.action((options) => {
|
|
14
|
+
const profiles = listProfiles();
|
|
15
|
+
const resolved = { baseUrl: resolveBaseUrl(), baseUrlSource: describeBaseUrlSource(), apiKeySource: describeApiKeySource() };
|
|
16
|
+
if (options.json) {
|
|
17
|
+
emitJsonSuccess({
|
|
18
|
+
configPath: getConfigPath(),
|
|
19
|
+
resolved,
|
|
20
|
+
profiles: profiles.map((p) => ({
|
|
21
|
+
name: p.name,
|
|
22
|
+
active: p.active,
|
|
23
|
+
email: p.profile.email ?? null,
|
|
24
|
+
role: p.profile.role ?? null,
|
|
25
|
+
keyPrefix: p.profile.keyPrefix ?? null,
|
|
26
|
+
baseUrl: p.profile.baseUrl ?? null
|
|
27
|
+
}))
|
|
28
|
+
});
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
console.log('');
|
|
32
|
+
console.log(dim(`config: ${getConfigPath()}`));
|
|
33
|
+
console.log(`base URL: ${cyan(resolved.baseUrl)} ${dim('(' + resolved.baseUrlSource + ')')}`);
|
|
34
|
+
console.log(`api key: ${dim(resolved.apiKeySource)}`);
|
|
35
|
+
console.log('');
|
|
36
|
+
if (profiles.length === 0) {
|
|
37
|
+
console.log(dim('No profiles. Run `wat login`.'));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
for (const p of profiles) {
|
|
41
|
+
const mark = p.active ? green('●') : dim('○');
|
|
42
|
+
const key = p.profile.apiKey ? maskApiKey(p.profile.apiKey) : '-';
|
|
43
|
+
console.log(`${mark} ${p.name} ${dim(p.profile.email ?? '')} ${dim('[' + key + ']')}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
console.log('');
|
|
47
|
+
});
|
|
48
|
+
configCommand
|
|
49
|
+
.command('clear')
|
|
50
|
+
.description('Remove the entire local config (all profiles)')
|
|
51
|
+
.option('--json', 'Output as JSON')
|
|
52
|
+
.action((options) => {
|
|
53
|
+
clearConfig();
|
|
54
|
+
if (options.json)
|
|
55
|
+
emitJsonSuccess({ cleared: true });
|
|
56
|
+
else
|
|
57
|
+
console.log(`${CHECK} ${green('Local config cleared.')}`);
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/cli/commands/config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,qBAAqB,EACrB,aAAa,EACb,YAAY,EACZ,UAAU,EACV,cAAc,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,EAAE,KAAK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AI;QAAE,eAAe,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;;QAChD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,IAAI,KAAK,CAAC,uBAAuB,CAAC,EAAE,CAAC,CAAC;AACjE,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wat login`
|
|
3
|
+
*
|
|
4
|
+
* Email-OTP login. Requests a code, prompts for it (and the WAT signup code on
|
|
5
|
+
* first enrollment), verifies + mints an API key, and saves it as the active
|
|
6
|
+
* profile in ~/.config/wat/config.json (mode 0600). The raw key is the secret —
|
|
7
|
+
* it is stored locally and sent as a Bearer token on every subsequent call.
|
|
8
|
+
*/
|
|
9
|
+
import { Command } from 'commander';
|
|
10
|
+
export declare const loginCommand: Command;
|
|
11
|
+
//# sourceMappingURL=login.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../../src/cli/commands/login.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmCpC,eAAO,MAAM,YAAY,SA8GrB,CAAC"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wat login`
|
|
3
|
+
*
|
|
4
|
+
* Email-OTP login. Requests a code, prompts for it (and the WAT signup code on
|
|
5
|
+
* first enrollment), verifies + mints an API key, and saves it as the active
|
|
6
|
+
* profile in ~/.config/wat/config.json (mode 0600). The raw key is the secret —
|
|
7
|
+
* it is stored locally and sent as a Bearer token on every subsequent call.
|
|
8
|
+
*/
|
|
9
|
+
import { Command } from 'commander';
|
|
10
|
+
import { createInterface } from 'node:readline/promises';
|
|
11
|
+
import { stdin, stdout } from 'node:process';
|
|
12
|
+
import { requestLoginOtp, completeLogin } from '../../utils/auth-flow-client.js';
|
|
13
|
+
import { PROGRAM_NAME, deriveProfileName, listProfiles, maskApiKey, setActiveProfile, upsertProfile, resolveBaseUrl, describeBaseUrlSource } from '../../utils/config.js';
|
|
14
|
+
import { CHECK, cyan, dim, emitJsonError, emitJsonSuccess, failHuman, green } from '../utils/output.js';
|
|
15
|
+
async function prompt(question) {
|
|
16
|
+
const rl = createInterface({ input: stdin, output: stdout });
|
|
17
|
+
try {
|
|
18
|
+
return (await rl.question(question)).trim();
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
rl.close();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export const loginCommand = new Command('login')
|
|
25
|
+
.description('Email-OTP login; mints + stores an API key')
|
|
26
|
+
.option('--email <email>', 'Email address (prompts if omitted)')
|
|
27
|
+
.option('--code <code>', '6-digit OTP (skips the interactive code prompt)')
|
|
28
|
+
.option('--signup-code <code>', 'WAT signup code (required on first enrollment)')
|
|
29
|
+
.option('--profile-name <name>', 'Local profile name (auto-derived if omitted)')
|
|
30
|
+
.option('--key-name <name>', 'Human-readable name for the minted API key')
|
|
31
|
+
.option('--api-url <url>', 'Override the API base URL')
|
|
32
|
+
.option('--json', 'Output as JSON')
|
|
33
|
+
.action(async (options) => {
|
|
34
|
+
const email = options.email ?? (await prompt('Email: '));
|
|
35
|
+
if (!email)
|
|
36
|
+
failHuman({ message: 'An email is required.' });
|
|
37
|
+
if (!options.json) {
|
|
38
|
+
console.log('');
|
|
39
|
+
console.log(dim(`Target: ${resolveBaseUrl(options.apiUrl)} (${describeBaseUrlSource(options.apiUrl)})`));
|
|
40
|
+
}
|
|
41
|
+
// 1) Request the OTP.
|
|
42
|
+
const req = await requestLoginOtp({ email, baseUrl: options.apiUrl });
|
|
43
|
+
if (!req.success) {
|
|
44
|
+
if (options.json)
|
|
45
|
+
emitJsonError(req.error, req.status);
|
|
46
|
+
else
|
|
47
|
+
failHuman(req.error);
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
50
|
+
// 2) Collect the code (+ signup code if needed).
|
|
51
|
+
const code = options.code ?? (await prompt('Code from your email: '));
|
|
52
|
+
if (!code)
|
|
53
|
+
failHuman({ message: 'A verification code is required.' });
|
|
54
|
+
// 3) Complete the login (mints the key). If the email is new, the signup
|
|
55
|
+
// code is required; retry once interactively when the server asks.
|
|
56
|
+
let signupCode = options.signupCode;
|
|
57
|
+
let result = await completeLogin({
|
|
58
|
+
email,
|
|
59
|
+
code,
|
|
60
|
+
...(signupCode ? { signupCode } : {}),
|
|
61
|
+
...(options.keyName ? { apiKey: { name: options.keyName } } : {}),
|
|
62
|
+
baseUrl: options.apiUrl
|
|
63
|
+
});
|
|
64
|
+
if (!result.success && result.error.code === 'NOT_AUTHORIZED' && !signupCode && !options.json) {
|
|
65
|
+
signupCode = await prompt('WAT signup code (first enrollment): ');
|
|
66
|
+
if (signupCode) {
|
|
67
|
+
result = await completeLogin({
|
|
68
|
+
email,
|
|
69
|
+
code,
|
|
70
|
+
signupCode,
|
|
71
|
+
...(options.keyName ? { apiKey: { name: options.keyName } } : {}),
|
|
72
|
+
baseUrl: options.apiUrl
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if (!result.success) {
|
|
77
|
+
if (options.json)
|
|
78
|
+
emitJsonError(result.error, result.status);
|
|
79
|
+
else
|
|
80
|
+
failHuman(result.error);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
}
|
|
83
|
+
// 4) Persist the key as the active profile.
|
|
84
|
+
const existingNames = new Set(listProfiles().map((p) => p.name));
|
|
85
|
+
const profileName = options.profileName ??
|
|
86
|
+
deriveProfileName({
|
|
87
|
+
email: result.data.member.email,
|
|
88
|
+
keyName: result.data.apiKey.name,
|
|
89
|
+
keyPrefix: result.data.apiKey.keyPrefix
|
|
90
|
+
}, existingNames);
|
|
91
|
+
upsertProfile(profileName, {
|
|
92
|
+
apiKey: result.data.apiKey.raw,
|
|
93
|
+
email: result.data.member.email,
|
|
94
|
+
role: result.data.member.role,
|
|
95
|
+
keyName: result.data.apiKey.name,
|
|
96
|
+
keyPrefix: result.data.apiKey.keyPrefix,
|
|
97
|
+
createdAt: result.data.apiKey.createdAt,
|
|
98
|
+
expiresAt: result.data.apiKey.expiresAt ?? null,
|
|
99
|
+
...(options.apiUrl ? { baseUrl: options.apiUrl } : {})
|
|
100
|
+
});
|
|
101
|
+
setActiveProfile(profileName);
|
|
102
|
+
if (options.json) {
|
|
103
|
+
emitJsonSuccess({
|
|
104
|
+
profileName,
|
|
105
|
+
created: result.data.created,
|
|
106
|
+
member: result.data.member,
|
|
107
|
+
apiKey: {
|
|
108
|
+
keyId: result.data.apiKey.keyId,
|
|
109
|
+
keyPrefix: result.data.apiKey.keyPrefix,
|
|
110
|
+
name: result.data.apiKey.name,
|
|
111
|
+
createdAt: result.data.apiKey.createdAt,
|
|
112
|
+
...(result.data.apiKey.expiresAt && { expiresAt: result.data.apiKey.expiresAt })
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
console.log('');
|
|
118
|
+
console.log(`${CHECK} ${green('Logged in')}`);
|
|
119
|
+
console.log('');
|
|
120
|
+
console.log(` Member: ${result.data.member.email} (${result.data.member.role})`);
|
|
121
|
+
console.log(` Profile: ${profileName} ${cyan('(now active)')}`);
|
|
122
|
+
console.log(` API key: ${maskApiKey(result.data.apiKey.raw)}`);
|
|
123
|
+
console.log('');
|
|
124
|
+
console.log(` Try it: ${cyan(`${PROGRAM_NAME} rooms list`)}`);
|
|
125
|
+
console.log('');
|
|
126
|
+
});
|
|
127
|
+
//# sourceMappingURL=login.js.map
|