@zeegme/cli 0.5.0 → 0.6.1

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 CHANGED
@@ -47,6 +47,8 @@ Plain `http` is accepted for `localhost` only. Each origin keeps its own login.
47
47
  | Command | What it does |
48
48
  |---|---|
49
49
  | `zeeg event-types list` / `get <uuid>` | Your event types (scheduling pages) |
50
+ | `zeeg event-types create --type --title [--language --data]` | Create an event type |
51
+ | `zeeg event-types update <uuid> [--title --language --data]` | Change an event type, its language included (`de-du` is German addressing the invitee as du) |
50
52
  | `zeeg availability <eventTypeUuid> [--from --to --tz]` | Open start times, by day |
51
53
  | `zeeg schedules list [--email]` | Availability schedules |
52
54
  | `zeeg time-off add --start --end --title [--type]` | Block days as time off |
@@ -1,6 +1,15 @@
1
1
  import { unwrap } from '../api/client.js';
2
+ import { UsageError } from '../errors.js';
2
3
  import { renderTable } from '../output.js';
3
- import { addDays, asJson, isoDate, localTimeZone, positiveInt } from './util.js';
4
+ import { addDays, asJson, isoDate, jsonArgument, localTimeZone, positiveInt } from './util.js';
5
+ /** The API answers 422 to any other code, so the CLI passes the value through unchecked. */
6
+ const LANGUAGE_HELP = 'language of the booking page and of invitee emails: en, de (German, formal), de-du (German, informal), nl, fi, es, fr, pl, da, sv or it';
7
+ const DATA_HELP = 'any other field of the API body, as a JSON object inline or as @file.json; the other flags win over it';
8
+ /** The `--data` object with the flags laid over it, leaving out the flags not given. */
9
+ async function writeBody(options, flags) {
10
+ const given = Object.fromEntries(Object.entries({ title: options.title, language: options.language, ...flags }).filter(([, value]) => value !== undefined));
11
+ return { ...(options.data === undefined ? {} : await jsonArgument(options.data)), ...given };
12
+ }
4
13
  export function registerEventTypes(program, context) {
5
14
  const eventTypes = program.command('event-types').description('Scheduling pages (event types)');
6
15
  eventTypes
@@ -31,6 +40,34 @@ export function registerEventTypes(program, context) {
31
40
  const data = asJson(await unwrap((await ctx.api()).GET('/event-types/{uuid}', { params: { path: { uuid } } })));
32
41
  ctx.print.record(data.resource);
33
42
  });
43
+ eventTypes
44
+ .command('create')
45
+ .description('Create an event type; it is bookable through its link at once')
46
+ .option('--type <type>', 'ONE_ON_ONE, GROUP, ROUND_ROBIN or COLLECTIVE')
47
+ .option('--title <title>', 'the name invitees see')
48
+ .option('--language <code>', `${LANGUAGE_HELP} (default: your own)`)
49
+ .option('--data <json>', DATA_HELP)
50
+ .action(async (options) => {
51
+ const ctx = context();
52
+ const body = await writeBody(options, { type: options.type });
53
+ const data = asJson(await unwrap((await ctx.api()).POST('/event-types', { body: body })));
54
+ ctx.print.record(data.resource);
55
+ });
56
+ eventTypes
57
+ .command('update <uuid>')
58
+ .description('Change an event type; a field left out keeps its value')
59
+ .option('--title <title>', 'the name invitees see')
60
+ .option('--language <code>', LANGUAGE_HELP)
61
+ .option('--data <json>', DATA_HELP)
62
+ .action(async (uuid, options) => {
63
+ const ctx = context();
64
+ const body = await writeBody(options, {});
65
+ if (Object.keys(body).length === 0) {
66
+ throw new UsageError('Pass what to change: --title, --language or --data.');
67
+ }
68
+ const data = asJson(await unwrap((await ctx.api()).PATCH('/event-types/{uuid}', { params: { path: { uuid } }, body: body })));
69
+ ctx.print.record(data.resource);
70
+ });
34
71
  program
35
72
  .command('availability <eventTypeUuid>')
36
73
  .description('Available start times for an event type (needs a paid plan)')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zeegme/cli",
3
- "version": "0.5.0",
3
+ "version": "0.6.1",
4
4
  "description": "The Zeeg command line: bookings, availability, notes, CRM, routing forms and AI phone calls from your terminal.",
5
5
  "license": "MIT",
6
6
  "type": "module",