@infaris/calendar-cli 0.14.0 → 0.15.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/README.md +30 -4
- package/dist/auth.js +1 -1
- package/dist/config.js +1 -1
- package/dist/crm-admin.js +21 -1
- package/dist/crm-index.js +5 -3
- package/dist/crm-quote.js +1 -1
- package/dist/crm-recurring.js +198 -0
- package/dist/freebusy.js +1 -1
- package/dist/hours-cli.js +3 -3
- package/dist/index.js +14 -8
- package/dist/selectors.js +11 -5
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -105,12 +105,12 @@ infaris-calendar agenda --week # current week (Mon-Sun)
|
|
|
105
105
|
infaris-calendar agenda --month
|
|
106
106
|
infaris-calendar agenda --days 7 # next 7 days
|
|
107
107
|
infaris-calendar agenda --from 2026-07-01 --to 2026-07-07
|
|
108
|
-
infaris-calendar agenda --calendar
|
|
108
|
+
infaris-calendar agenda --calendar Gezin # one calendar only (name or id)
|
|
109
109
|
infaris-calendar agenda --week --json # full details for an AI assistant
|
|
110
110
|
```
|
|
111
111
|
|
|
112
112
|
Calendars you've turned off (hidden) in Calendar are excluded, just like in
|
|
113
|
-
the web app. Pass `--include-hidden` to show them, or `--calendar <id>` to target
|
|
113
|
+
the web app. Pass `--include-hidden` to show them, or `--calendar <id-or-name>` to target
|
|
114
114
|
one specific calendar regardless of its visibility.
|
|
115
115
|
|
|
116
116
|
Recurring events are expanded into individual occurrences within the range by
|
|
@@ -130,7 +130,7 @@ Agenda options:
|
|
|
130
130
|
| `--days <n>` | Number of days from `--from` or today |
|
|
131
131
|
| `--today` / `--tomorrow` | Single day (today is the default) |
|
|
132
132
|
| `--week` / `--month` | Current week (Mon-Sun) / calendar month |
|
|
133
|
-
| `--calendar <id>` | Only events from this calendar
|
|
133
|
+
| `--calendar <id-or-name>` | Only events from this calendar |
|
|
134
134
|
| `--search <text>` | Filter by title, description or location |
|
|
135
135
|
| `--include-hidden` | Also include calendars you turned off |
|
|
136
136
|
| `--no-expand` | Do not expand recurring events |
|
|
@@ -212,7 +212,7 @@ infaris-calendar free --week --json # for an AI to pick a slo
|
|
|
212
212
|
| `--min <minutes>` | Minimum slot length to report | `30` |
|
|
213
213
|
| `--include-weekends` | Include Saturday and Sunday | your settings |
|
|
214
214
|
| `--ignore-all-day` | Don't treat all-day events as busy | off |
|
|
215
|
-
| `--calendar <id>` | Only consider this calendar as busy | all |
|
|
215
|
+
| `--calendar <id-or-name>` | Only consider this calendar as busy | all |
|
|
216
216
|
| `--json` | Output slots as JSON | — |
|
|
217
217
|
|
|
218
218
|
## Show, reschedule or delete an event
|
|
@@ -584,6 +584,32 @@ moves contacts and history and archives the duplicate; it refuses a duplicate wi
|
|
|
584
584
|
quotes, invoices or a Guard workspace and does not move Calendar tickets. `tidy` is a dry run
|
|
585
585
|
until `--apply`. Support must be deployed with these routes before the commands work.
|
|
586
586
|
|
|
587
|
+
## Billing address and recurring invoices (0.15.0)
|
|
588
|
+
|
|
589
|
+
```bash
|
|
590
|
+
infaris-crm update RELATION --legal-name "Name BV" --address-line1 "Street 1" --postal-code "1234 AB" \
|
|
591
|
+
--city Rotterdam --country NL [--address-line2 ...] [--vat-number ...] [--kvk-number ...]
|
|
592
|
+
infaris-crm recurring create --customer RELATION --title Hosting \
|
|
593
|
+
--line "Hosting;1;30,00;21" [--line ...] --interval 1 --start 2026-11-23 \
|
|
594
|
+
[--ends 2027-12-31] [--days-until-due 14] [--auto-send] [--dry-run]
|
|
595
|
+
infaris-crm recurring create --file recurring.json --dry-run # API shape, flags override
|
|
596
|
+
infaris-crm recurring list [--customer RELATION] [--include-inactive]
|
|
597
|
+
infaris-crm recurring show ID # schedule, lines, totals, billing data, warnings
|
|
598
|
+
infaris-crm recurring update ID [--title ...] [--line ...] [--start NEXT_DATE] [--no-auto-send] [--no-ends]
|
|
599
|
+
infaris-crm recurring pause ID | resume ID
|
|
600
|
+
infaris-crm recurring generate ID --yes # one invoice now, moves the schedule on
|
|
601
|
+
infaris-crm recurring delete ID --yes # generated invoices stay
|
|
602
|
+
```
|
|
603
|
+
|
|
604
|
+
The address goes to the Stripe customer: set it before the first invoice (an
|
|
605
|
+
existing Stripe customer is updated straight away). A `--line` is
|
|
606
|
+
`description;quantity;price excl. VAT in euro;VAT %` (VAT defaults to 21);
|
|
607
|
+
`--line` on `update` replaces all lines. Support's daily cron
|
|
608
|
+
(`/api/cron/recurring`) generates every invoice whose date has come; with
|
|
609
|
+
`--auto-send` it goes out through Stripe to the relation's e-mail address,
|
|
610
|
+
otherwise it stays a draft in Support. `create` and `show` return `warnings`
|
|
611
|
+
when the e-mail or billing address is missing. Dates are calendar days (UTC).
|
|
612
|
+
|
|
587
613
|
## Quotes in Support (0.12.0)
|
|
588
614
|
|
|
589
615
|
`infaris-crm quote` creates Guard quotes as drafts in Support, priced from the
|
package/dist/auth.js
CHANGED
|
@@ -372,7 +372,7 @@ async function rotate(creds) {
|
|
|
372
372
|
throw new Error("Your session has expired. Please run `infaris-calendar login` again " +
|
|
373
373
|
"(or `infaris-calendar login link` from an agent or SSH session). " +
|
|
374
374
|
"If this keeps happening, an older infaris-calendar in another worktree " +
|
|
375
|
-
"may share ~/.infaris/calendar and rotate the same session; update or remove it.");
|
|
375
|
+
"may share ~/.infaris/calendar and rotate the same session; update or remove it.", { cause: err });
|
|
376
376
|
}
|
|
377
377
|
const updated = toCredentials(creds.baseUrl, tokens);
|
|
378
378
|
// Keep the old refresh token if the server did not send a new one.
|
package/dist/config.js
CHANGED
|
@@ -139,7 +139,7 @@ export async function withRefreshLock(fn) {
|
|
|
139
139
|
continue;
|
|
140
140
|
}
|
|
141
141
|
if (Date.now() > deadline) {
|
|
142
|
-
throw new Error("Another infaris-calendar process is refreshing the session. Try again in a moment.");
|
|
142
|
+
throw new Error("Another infaris-calendar process is refreshing the session. Try again in a moment.", { cause: err });
|
|
143
143
|
}
|
|
144
144
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
145
145
|
}
|
package/dist/crm-admin.js
CHANGED
|
@@ -42,6 +42,16 @@ export function planTidy(items) {
|
|
|
42
42
|
}
|
|
43
43
|
return changes;
|
|
44
44
|
}
|
|
45
|
+
/** Billing fields; Support copies them to the Stripe customer. */
|
|
46
|
+
const ADDRESS_OPTIONS = [
|
|
47
|
+
"addressLine1",
|
|
48
|
+
"addressLine2",
|
|
49
|
+
"postalCode",
|
|
50
|
+
"city",
|
|
51
|
+
"country",
|
|
52
|
+
"vatNumber",
|
|
53
|
+
"kvkNumber",
|
|
54
|
+
];
|
|
45
55
|
function patch(customer, body) {
|
|
46
56
|
return crmFetch(`/relations/${encodeURIComponent(customer)}`, {
|
|
47
57
|
method: "PATCH",
|
|
@@ -52,13 +62,20 @@ function patch(customer, body) {
|
|
|
52
62
|
export function registerAdminCommands(program) {
|
|
53
63
|
program
|
|
54
64
|
.command("update <customer>")
|
|
55
|
-
.description("Edit a customer's name, contact data, status or kind (pass only what changes)")
|
|
65
|
+
.description("Edit a customer's name, contact data, billing address, status or kind (pass only what changes; \"\" clears)")
|
|
56
66
|
.option("--name <name>")
|
|
57
67
|
.option("--legal-name <name>")
|
|
58
68
|
.option("--email <email>")
|
|
59
69
|
.option("--phone <phone>")
|
|
60
70
|
.option("--website <url>")
|
|
61
71
|
.option("--contact-person <name>")
|
|
72
|
+
.option("--address-line1 <text>", "Billing address: street and number")
|
|
73
|
+
.option("--address-line2 <text>")
|
|
74
|
+
.option("--postal-code <code>")
|
|
75
|
+
.option("--city <city>")
|
|
76
|
+
.option("--country <code>", "Country code, for example NL")
|
|
77
|
+
.option("--vat-number <number>")
|
|
78
|
+
.option("--kvk-number <number>")
|
|
62
79
|
.addOption(new Option("--status <status>").choices([
|
|
63
80
|
"PROSPECT",
|
|
64
81
|
"ACTIVE",
|
|
@@ -81,6 +98,9 @@ export function registerAdminCommands(program) {
|
|
|
81
98
|
body.website = opts.website;
|
|
82
99
|
if (opts.contactPerson !== undefined)
|
|
83
100
|
body.contactPerson = opts.contactPerson;
|
|
101
|
+
for (const key of ADDRESS_OPTIONS)
|
|
102
|
+
if (opts[key] !== undefined)
|
|
103
|
+
body[key] = opts[key];
|
|
84
104
|
if (opts.status !== undefined)
|
|
85
105
|
body.status = opts.status;
|
|
86
106
|
if (opts.kind !== undefined)
|
package/dist/crm-index.js
CHANGED
|
@@ -6,12 +6,13 @@ import { clearCredentials, DEFAULT_BASE_URL } from "./config.js";
|
|
|
6
6
|
import { crmFetch } from "./crm-api.js";
|
|
7
7
|
import { registerAdminCommands, RELATION_KINDS } from "./crm-admin.js";
|
|
8
8
|
import { registerQuoteCommands } from "./crm-quote.js";
|
|
9
|
+
import { registerRecurringCommands } from "./crm-recurring.js";
|
|
9
10
|
import { createTask, addTaskAttachment, listTeamMembers, listTasks, } from "./api.js";
|
|
10
11
|
import { resolveAttendeeIds } from "./selectors.js";
|
|
11
12
|
const program = new Command()
|
|
12
13
|
.name("infaris-crm")
|
|
13
|
-
.version("0.
|
|
14
|
-
.description("Customer dossiers, contact people, contact history and
|
|
14
|
+
.version("0.15.0")
|
|
15
|
+
.description("Customer dossiers, contact people, contact history, quotes and recurring invoices. Shares infaris-calendar login.");
|
|
15
16
|
function output(value) {
|
|
16
17
|
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
17
18
|
}
|
|
@@ -152,7 +153,7 @@ program
|
|
|
152
153
|
attachments.push((await addTaskAttachment(task.id, path)).attachment);
|
|
153
154
|
}
|
|
154
155
|
catch (error) {
|
|
155
|
-
throw new Error(`Ticket #${task.taskKey} was created at ${baseUrl}/t/${task.taskKey}. Upload failed; retry with infaris-calendar attach task --id ${task.taskKey}, not ticket. ${error instanceof Error ? error.message : error}
|
|
156
|
+
throw new Error(`Ticket #${task.taskKey} was created at ${baseUrl}/t/${task.taskKey}. Upload failed; retry with infaris-calendar attach task --id ${task.taskKey}, not ticket. ${error instanceof Error ? error.message : error}`, { cause: error });
|
|
156
157
|
}
|
|
157
158
|
}
|
|
158
159
|
output({ task, attachments, url: `${baseUrl}/t/${task.taskKey}` });
|
|
@@ -222,6 +223,7 @@ program
|
|
|
222
223
|
});
|
|
223
224
|
registerAdminCommands(program);
|
|
224
225
|
registerQuoteCommands(program);
|
|
226
|
+
registerRecurringCommands(program);
|
|
225
227
|
program.parseAsync(process.argv).catch((error) => {
|
|
226
228
|
process.stderr.write(`Error: ${error instanceof Error ? error.message : String(error)}\n`);
|
|
227
229
|
process.exitCode = 1;
|
package/dist/crm-quote.js
CHANGED
|
@@ -65,7 +65,7 @@ async function quoteApi(call) {
|
|
|
65
65
|
}
|
|
66
66
|
catch (error) {
|
|
67
67
|
if (error instanceof Error && /\(404\): Not Found$|\(404\): $/.test(error.message))
|
|
68
|
-
throw new Error("Support has no quote API yet (deploy Support with /api/crm/quotes first)");
|
|
68
|
+
throw new Error("Support has no quote API yet (deploy Support with /api/crm/quotes first)", { cause: error });
|
|
69
69
|
throw error;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { Option } from "commander";
|
|
3
|
+
import { crmFetch } from "./crm-api.js";
|
|
4
|
+
const INTERVALS = ["1", "3", "6", "12"];
|
|
5
|
+
/** Euro amount as typed ("30", "30,00", "1.250,50", "1250.50") to whole cents. */
|
|
6
|
+
export function euroToCents(value) {
|
|
7
|
+
let text = value.trim().replace(/^€\s*/, "").replace(/\s/g, "");
|
|
8
|
+
if (/,\d{1,2}$/.test(text))
|
|
9
|
+
text = text.replace(/\./g, "").replace(",", ".");
|
|
10
|
+
else if (/^-?\d{1,3}(,\d{3})+(\.\d{1,2})?$/.test(text))
|
|
11
|
+
text = text.replace(/,/g, "");
|
|
12
|
+
if (!/^-?\d+(\.\d{1,2})?$/.test(text))
|
|
13
|
+
throw new Error(`Invalid amount "${value}"`);
|
|
14
|
+
return Math.round(Number(text) * 100);
|
|
15
|
+
}
|
|
16
|
+
/** "description;quantity;price-euro;vat" (vat defaults to 21) to an API line. */
|
|
17
|
+
export function parseLine(spec) {
|
|
18
|
+
const parts = spec.split(";").map((part) => part.trim());
|
|
19
|
+
if (parts.length < 3 || parts.length > 4)
|
|
20
|
+
throw new Error(`--line "${spec}" must be "description;quantity;price-euro;vat"`);
|
|
21
|
+
const [description, quantity, price, vat = "21"] = parts;
|
|
22
|
+
if (!description)
|
|
23
|
+
throw new Error(`--line "${spec}" has no description`);
|
|
24
|
+
const qty = Number(quantity.replace(",", "."));
|
|
25
|
+
if (!Number.isFinite(qty) || qty <= 0)
|
|
26
|
+
throw new Error(`--line "${spec}" has an invalid quantity`);
|
|
27
|
+
const vatRate = Number(vat.replace(/%$/, "").replace(",", "."));
|
|
28
|
+
if (!Number.isFinite(vatRate) || vatRate < 0 || vatRate > 100)
|
|
29
|
+
throw new Error(`--line "${spec}" has an invalid VAT rate`);
|
|
30
|
+
return { description, quantity: qty, unitPriceCents: euroToCents(price), vatRate };
|
|
31
|
+
}
|
|
32
|
+
function day(value, flag) {
|
|
33
|
+
if (!/^\d{4}-\d{2}-\d{2}$/.test(value))
|
|
34
|
+
throw new Error(`${flag} must be YYYY-MM-DD`);
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
function positiveInt(value, flag) {
|
|
38
|
+
const n = Number(value);
|
|
39
|
+
if (!Number.isInteger(n) || n < 1)
|
|
40
|
+
throw new Error(`${flag} must be a positive whole number`);
|
|
41
|
+
return n;
|
|
42
|
+
}
|
|
43
|
+
/** Body for create: the --file JSON (API shape) with flags on top. */
|
|
44
|
+
export function buildCreateBody(opts) {
|
|
45
|
+
const body = opts.file
|
|
46
|
+
? JSON.parse(readFileSync(opts.file === "-" ? 0 : opts.file, "utf8"))
|
|
47
|
+
: {};
|
|
48
|
+
if (!body || typeof body !== "object" || Array.isArray(body))
|
|
49
|
+
throw new Error(`${opts.file} must hold a JSON object`);
|
|
50
|
+
if (opts.customer)
|
|
51
|
+
body.relation = opts.customer;
|
|
52
|
+
Object.assign(body, scheduleFields(opts));
|
|
53
|
+
if (opts.dryRun)
|
|
54
|
+
body.dryRun = true;
|
|
55
|
+
if (!body.relation)
|
|
56
|
+
throw new Error("Pass --customer (relation number)");
|
|
57
|
+
if (!body.title)
|
|
58
|
+
throw new Error("Pass --title");
|
|
59
|
+
if (!body.startDate)
|
|
60
|
+
throw new Error("Pass --start YYYY-MM-DD (first invoice date)");
|
|
61
|
+
if (!Array.isArray(body.lines) || !body.lines.length)
|
|
62
|
+
throw new Error('Pass at least one --line "description;quantity;price-euro;vat"');
|
|
63
|
+
return body;
|
|
64
|
+
}
|
|
65
|
+
function scheduleFields(opts) {
|
|
66
|
+
const body = {};
|
|
67
|
+
if (opts.title !== undefined)
|
|
68
|
+
body.title = opts.title;
|
|
69
|
+
if (opts.notes !== undefined)
|
|
70
|
+
body.notes = opts.notes || null;
|
|
71
|
+
if (opts.line?.length)
|
|
72
|
+
body.lines = opts.line.map(parseLine);
|
|
73
|
+
if (opts.interval !== undefined)
|
|
74
|
+
body.intervalMonths = Number(opts.interval);
|
|
75
|
+
if (opts.start !== undefined)
|
|
76
|
+
body.startDate = day(opts.start, "--start");
|
|
77
|
+
if (opts.ends !== undefined)
|
|
78
|
+
body.endsAt = day(opts.ends, "--ends");
|
|
79
|
+
if (opts.noEnds)
|
|
80
|
+
body.endsAt = null;
|
|
81
|
+
if (opts.daysUntilDue !== undefined)
|
|
82
|
+
body.daysUntilDue = positiveInt(opts.daysUntilDue, "--days-until-due");
|
|
83
|
+
if (opts.autoSend !== undefined)
|
|
84
|
+
body.autoSend = opts.autoSend;
|
|
85
|
+
return body;
|
|
86
|
+
}
|
|
87
|
+
/** Body for update: only what changes; --start moves the next run. */
|
|
88
|
+
export function buildUpdateBody(opts) {
|
|
89
|
+
const { startDate, ...body } = scheduleFields(opts);
|
|
90
|
+
if (startDate)
|
|
91
|
+
body.nextRunAt = startDate;
|
|
92
|
+
if (!Object.keys(body).length)
|
|
93
|
+
throw new Error("Pass at least one field to change");
|
|
94
|
+
return body;
|
|
95
|
+
}
|
|
96
|
+
function output(value) {
|
|
97
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
98
|
+
}
|
|
99
|
+
const enc = encodeURIComponent;
|
|
100
|
+
const json = (method, body) => ({
|
|
101
|
+
method,
|
|
102
|
+
headers: { "content-type": "application/json" },
|
|
103
|
+
body: JSON.stringify(body),
|
|
104
|
+
});
|
|
105
|
+
/** A Support without the recurring API answers 404 on the collection route. */
|
|
106
|
+
async function recurringApi(call) {
|
|
107
|
+
try {
|
|
108
|
+
return await call();
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
if (error instanceof Error && /\(404\): (Not Found)?$/.test(error.message))
|
|
112
|
+
throw new Error("Support has no recurring-invoice API yet (deploy Support with /api/crm/recurring first)", { cause: error });
|
|
113
|
+
throw error;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function scheduleOptions(command, create) {
|
|
117
|
+
command
|
|
118
|
+
.option("--title <title>", "Invoice title")
|
|
119
|
+
.option("--line <spec...>", 'Invoice line "description;quantity;price-euro excl. VAT;vat%" (repeat; replaces all lines on update)')
|
|
120
|
+
.addOption(new Option("--interval <months>", "Every 1, 3, 6 or 12 months").choices(INTERVALS))
|
|
121
|
+
.option("--start <date>", create ? "First invoice date YYYY-MM-DD" : "Move the next invoice date (YYYY-MM-DD)")
|
|
122
|
+
.option("--ends <date>", "Last date an invoice may be generated (YYYY-MM-DD)")
|
|
123
|
+
.option("--days-until-due <days>", "Payment term in days (default 14)")
|
|
124
|
+
.option("--notes <text>", "Internal note, also in the invoice notes")
|
|
125
|
+
.option("--auto-send", "Send each invoice through Stripe to the relation's e-mail")
|
|
126
|
+
.option("--json", "Machine-readable output (default)");
|
|
127
|
+
if (!create) {
|
|
128
|
+
command.option("--no-auto-send", "Generate drafts only");
|
|
129
|
+
command.option("--no-ends", "Remove the end date");
|
|
130
|
+
}
|
|
131
|
+
return command;
|
|
132
|
+
}
|
|
133
|
+
export function registerRecurringCommands(program) {
|
|
134
|
+
const recurring = program
|
|
135
|
+
.command("recurring")
|
|
136
|
+
.description("Recurring invoices in Support (generated daily; auto-send goes out through Stripe)");
|
|
137
|
+
recurring
|
|
138
|
+
.command("list")
|
|
139
|
+
.description("List recurring invoices")
|
|
140
|
+
.option("--customer <relation>", "Only this relation")
|
|
141
|
+
.option("--include-inactive", "Also paused and ended ones")
|
|
142
|
+
.option("--json", "Machine-readable output (default)")
|
|
143
|
+
.action(async (opts) => {
|
|
144
|
+
const params = new URLSearchParams();
|
|
145
|
+
if (opts.customer)
|
|
146
|
+
params.set("relation", opts.customer);
|
|
147
|
+
if (opts.includeInactive)
|
|
148
|
+
params.set("includeInactive", "1");
|
|
149
|
+
output(await recurringApi(() => crmFetch(`/recurring?${params}`)));
|
|
150
|
+
});
|
|
151
|
+
recurring
|
|
152
|
+
.command("show <id>")
|
|
153
|
+
.description("Schedule, lines, totals and the relation's billing data, with warnings")
|
|
154
|
+
.option("--json", "Machine-readable output (default)")
|
|
155
|
+
.action(async (id) => output(await recurringApi(() => crmFetch(`/recurring/${enc(id)}`))));
|
|
156
|
+
scheduleOptions(recurring
|
|
157
|
+
.command("create")
|
|
158
|
+
.description("Create a recurring invoice for a relation")
|
|
159
|
+
.option("--customer <relation>", "Relation number")
|
|
160
|
+
.option("--file <path>", "JSON body in the API shape (relation, title, lines with unitPriceCents, ...); flags override, '-' for stdin")
|
|
161
|
+
.option("--dry-run", "Show what would be created, with totals and warnings; write nothing"), true).action(async (opts) => {
|
|
162
|
+
const body = buildCreateBody({ ...opts, autoSend: opts.autoSend || undefined });
|
|
163
|
+
output(await recurringApi(() => crmFetch("/recurring", json("POST", body))));
|
|
164
|
+
});
|
|
165
|
+
scheduleOptions(recurring.command("update <id>").description("Change title, lines, schedule, payment term or auto-send"), false).action(async (id, opts) => {
|
|
166
|
+
// With both --x and --no-x defined, commander leaves an untyped flag undefined.
|
|
167
|
+
const body = buildUpdateBody({
|
|
168
|
+
...opts,
|
|
169
|
+
ends: typeof opts.ends === "string" ? opts.ends : undefined,
|
|
170
|
+
noEnds: opts.ends === false,
|
|
171
|
+
});
|
|
172
|
+
output(await recurringApi(() => crmFetch(`/recurring/${enc(id)}`, json("PATCH", body))));
|
|
173
|
+
});
|
|
174
|
+
for (const [name, active] of [["pause", false], ["resume", true]])
|
|
175
|
+
recurring
|
|
176
|
+
.command(`${name} <id>`)
|
|
177
|
+
.description(active ? "Resume generating invoices" : "Stop generating invoices until resumed")
|
|
178
|
+
.option("--json", "Machine-readable output (default)")
|
|
179
|
+
.action(async (id) => output(await recurringApi(() => crmFetch(`/recurring/${enc(id)}`, json("PATCH", { active })))));
|
|
180
|
+
recurring
|
|
181
|
+
.command("delete <id>")
|
|
182
|
+
.description("Delete a recurring invoice (invoices already generated stay)")
|
|
183
|
+
.option("--yes", "Confirm the deletion")
|
|
184
|
+
.action(async (id, opts) => {
|
|
185
|
+
if (!opts.yes)
|
|
186
|
+
throw new Error("Repeat with --yes to delete the recurring invoice");
|
|
187
|
+
output(await recurringApi(() => crmFetch(`/recurring/${enc(id)}`, json("DELETE", { confirm: id }))));
|
|
188
|
+
});
|
|
189
|
+
recurring
|
|
190
|
+
.command("generate <id>")
|
|
191
|
+
.description("Generate the next invoice now and move the schedule on (auto-send sends it through Stripe)")
|
|
192
|
+
.option("--yes", "Confirm generating (and possibly sending) an invoice")
|
|
193
|
+
.action(async (id, opts) => {
|
|
194
|
+
if (!opts.yes)
|
|
195
|
+
throw new Error("Generating creates an invoice now and, with auto-send, mails it through Stripe. Repeat with --yes");
|
|
196
|
+
output(await recurringApi(() => crmFetch(`/recurring/${enc(id)}/generate`, json("POST", { confirm: id }))));
|
|
197
|
+
});
|
|
198
|
+
}
|
package/dist/freebusy.js
CHANGED
|
@@ -48,7 +48,7 @@ export function computeFreeSlots(events, opts) {
|
|
|
48
48
|
const workEnd = new Date(day);
|
|
49
49
|
workEnd.setHours(opts.workEnd.h, opts.workEnd.m, 0, 0);
|
|
50
50
|
// Clamp the working window to the requested range and to "now".
|
|
51
|
-
|
|
51
|
+
const windowStart = Math.max(workStart.getTime(), opts.rangeStart.getTime(), now.getTime());
|
|
52
52
|
const windowEnd = Math.min(workEnd.getTime(), opts.rangeEnd.getTime());
|
|
53
53
|
if (windowStart >= windowEnd)
|
|
54
54
|
continue;
|
package/dist/hours-cli.js
CHANGED
|
@@ -51,7 +51,7 @@ function printHoursList(hours, userId, baseUrl) {
|
|
|
51
51
|
const notes = (entry.notes ?? "").replace(/\s+/g, " ").trim();
|
|
52
52
|
process.stdout.write(`${entry.workedOn} ${day.padEnd(2)} ${formatMinutes(entry.minutes).padEnd(8)} ${notes}\n`);
|
|
53
53
|
}
|
|
54
|
-
process.stdout.write(`\n${formatMinutes(total)} over ${mine.length} dag(en)
|
|
54
|
+
process.stdout.write(`\n${formatMinutes(total)} over ${mine.length} dag(en): ${hoursDashboardUrl(baseUrl)}\n`);
|
|
55
55
|
}
|
|
56
56
|
function toTaskRef(task) {
|
|
57
57
|
return {
|
|
@@ -159,7 +159,7 @@ async function writeDayLog(input) {
|
|
|
159
159
|
return;
|
|
160
160
|
}
|
|
161
161
|
fail(`${input.date} heeft al ${formatMinutes(input.existing.minutes)}` +
|
|
162
|
-
`${input.existing.notes ?
|
|
162
|
+
`${input.existing.notes ? `, ${input.existing.notes}` : ""}. ` +
|
|
163
163
|
`Gebruik --replace om te overschrijven.`);
|
|
164
164
|
}
|
|
165
165
|
const { entry, baseUrl } = await upsertHours({
|
|
@@ -242,7 +242,7 @@ export function registerHoursCommands(program) {
|
|
|
242
242
|
}
|
|
243
243
|
if (draft.existing) {
|
|
244
244
|
process.stdout.write(` bestaat al: ${formatMinutes(draft.existing.minutes)}` +
|
|
245
|
-
`${draft.existing.notes ?
|
|
245
|
+
`${draft.existing.notes ? `, ${draft.existing.notes}` : ""}\n`);
|
|
246
246
|
}
|
|
247
247
|
process.stdout.write(` ${draft.dashboardUrl}\n`);
|
|
248
248
|
if (!opts.write) {
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { addTaskAttachment, getTaskContext, commentOnTask, linkTaskPullRequest,
|
|
|
7
7
|
import { formatDayHeading, formatTime, localDayKey, parseDateInput, resolveRange, startOfDay, endOfDay, } from "./dates.js";
|
|
8
8
|
import { computeFreeSlots, parseHm } from "./freebusy.js";
|
|
9
9
|
import { resolveCreateEventTimes } from "./event-input.js";
|
|
10
|
-
import { resolveAttendeeIds, resolveWritableCalendarId } from "./selectors.js";
|
|
10
|
+
import { resolveAttendeeIds, resolveCalendarId, resolveWritableCalendarId, } from "./selectors.js";
|
|
11
11
|
import { crmFetch } from "./crm-api.js";
|
|
12
12
|
import { downloadTaskAttachments } from "./task-download.js";
|
|
13
13
|
import { registerHoursCommands } from "./hours-cli.js";
|
|
@@ -25,7 +25,7 @@ const program = new Command();
|
|
|
25
25
|
program
|
|
26
26
|
.name("infaris-calendar")
|
|
27
27
|
.description("Calendar CLI: agenda, tasks, mail drafts, and the urenstaat (hours).")
|
|
28
|
-
.version("0.
|
|
28
|
+
.version("0.15.0");
|
|
29
29
|
const loginCmd = program
|
|
30
30
|
.command("login")
|
|
31
31
|
.description("Sign in with Infaris in your browser and store a token")
|
|
@@ -152,6 +152,12 @@ async function loadCalendarInfo() {
|
|
|
152
152
|
return { names, visible, loaded: false };
|
|
153
153
|
}
|
|
154
154
|
}
|
|
155
|
+
/** Resolve a read-side `--calendar` value (id or name) to an id. */
|
|
156
|
+
async function resolveCalendarOption(selector) {
|
|
157
|
+
if (!selector)
|
|
158
|
+
return undefined;
|
|
159
|
+
return resolveCalendarId(selector, (await listCalendars()).accounts);
|
|
160
|
+
}
|
|
155
161
|
/**
|
|
156
162
|
* Hide events from calendars the user turned off, mirroring the web app. Skipped
|
|
157
163
|
* when --include-hidden is set, when a specific --calendar was requested, or when
|
|
@@ -234,7 +240,7 @@ async function runAgenda(opts) {
|
|
|
234
240
|
const { events: allEvents, baseUrl } = await listEvents({
|
|
235
241
|
start,
|
|
236
242
|
end,
|
|
237
|
-
calendarId: opts.calendar,
|
|
243
|
+
calendarId: await resolveCalendarOption(opts.calendar),
|
|
238
244
|
expand: opts.expand,
|
|
239
245
|
});
|
|
240
246
|
const visibleEvents = filterVisible(allEvents, calendarInfo, opts);
|
|
@@ -285,7 +291,7 @@ const agendaRangeOption = (cmd) => cmd
|
|
|
285
291
|
.option("--tomorrow", "Only tomorrow")
|
|
286
292
|
.option("--week", "The current week (Mon-Sun)")
|
|
287
293
|
.option("--month", "The current calendar month")
|
|
288
|
-
.option("--calendar <id>", "Only events from this calendar
|
|
294
|
+
.option("--calendar <id-or-name>", "Only events from this calendar")
|
|
289
295
|
.option("--include-hidden", "Also include calendars you turned off")
|
|
290
296
|
.option("--no-expand", "Do not expand recurring events into occurrences")
|
|
291
297
|
.option("--json", "Output events as JSON");
|
|
@@ -399,7 +405,7 @@ create
|
|
|
399
405
|
attachments = await attachImages(task.id, opts.image);
|
|
400
406
|
}
|
|
401
407
|
catch (error) {
|
|
402
|
-
throw new Error(`Task #${task.taskKey} was created at ${baseUrl}/t/${task.taskKey}; attachment upload failed. Use attach task --id ${task.taskKey} to retry uploads, not create task. ${error instanceof Error ? error.message : error}
|
|
408
|
+
throw new Error(`Task #${task.taskKey} was created at ${baseUrl}/t/${task.taskKey}; attachment upload failed. Use attach task --id ${task.taskKey} to retry uploads, not create task. ${error instanceof Error ? error.message : error}`, { cause: error });
|
|
403
409
|
}
|
|
404
410
|
if (opts.json) {
|
|
405
411
|
process.stdout.write(`${JSON.stringify({ ...task, attachments }, null, 2)}\n`);
|
|
@@ -474,7 +480,7 @@ program
|
|
|
474
480
|
.description("Show your next upcoming event(s)")
|
|
475
481
|
.option("-n, --limit <n>", "How many upcoming events to show", "3")
|
|
476
482
|
.option("--days <n>", "How many days ahead to look", "30")
|
|
477
|
-
.option("--calendar <id>", "Only events from this calendar
|
|
483
|
+
.option("--calendar <id-or-name>", "Only events from this calendar")
|
|
478
484
|
.option("--include-hidden", "Also include calendars you turned off")
|
|
479
485
|
.option("--json", "Output as JSON")
|
|
480
486
|
.action(async (opts) => {
|
|
@@ -488,7 +494,7 @@ program
|
|
|
488
494
|
const { events: allEvents, baseUrl } = await listEvents({
|
|
489
495
|
start: now,
|
|
490
496
|
end,
|
|
491
|
-
calendarId: opts.calendar,
|
|
497
|
+
calendarId: await resolveCalendarOption(opts.calendar),
|
|
492
498
|
expand: true,
|
|
493
499
|
});
|
|
494
500
|
const upcoming = filterVisible(allEvents, calendarInfo, opts)
|
|
@@ -548,7 +554,7 @@ agendaRangeOption(program
|
|
|
548
554
|
const { events: allEvents } = await listEvents({
|
|
549
555
|
start,
|
|
550
556
|
end,
|
|
551
|
-
calendarId: opts.calendar,
|
|
557
|
+
calendarId: await resolveCalendarOption(opts.calendar),
|
|
552
558
|
expand: opts.expand,
|
|
553
559
|
});
|
|
554
560
|
const events = filterVisible(allEvents, calendarInfo, opts);
|
package/dist/selectors.js
CHANGED
|
@@ -34,16 +34,22 @@ export function resolveAttendeeIds(selectors, members) {
|
|
|
34
34
|
}
|
|
35
35
|
return [...new Set(resolved)];
|
|
36
36
|
}
|
|
37
|
-
|
|
38
|
-
const writable = accounts.flatMap((account) => account.calendars.filter((calendar) => !calendar.isReadOnly));
|
|
37
|
+
function resolveCalendarIdFrom(selector, calendars, label) {
|
|
39
38
|
const needle = normalize(selector);
|
|
40
|
-
const matches =
|
|
39
|
+
const matches = calendars.filter((calendar) => calendar.id === selector || normalize(calendar.name) === needle);
|
|
41
40
|
if (matches.length === 0) {
|
|
42
|
-
const available =
|
|
43
|
-
throw new Error(`Unknown
|
|
41
|
+
const available = calendars.map((calendar) => calendar.name).join(", ");
|
|
42
|
+
throw new Error(`Unknown ${label} "${selector}".${available ? ` Available: ${available}.` : ""}`);
|
|
44
43
|
}
|
|
45
44
|
if (matches.length > 1) {
|
|
46
45
|
throw new Error(`Calendar name "${selector}" is ambiguous. Use its id.`);
|
|
47
46
|
}
|
|
48
47
|
return matches[0].id;
|
|
49
48
|
}
|
|
49
|
+
/** Any calendar the user can read (hidden and read-only included), by id or name. */
|
|
50
|
+
export function resolveCalendarId(selector, accounts) {
|
|
51
|
+
return resolveCalendarIdFrom(selector, accounts.flatMap((account) => account.calendars), "calendar");
|
|
52
|
+
}
|
|
53
|
+
export function resolveWritableCalendarId(selector, accounts) {
|
|
54
|
+
return resolveCalendarIdFrom(selector, accounts.flatMap((account) => account.calendars.filter((calendar) => !calendar.isReadOnly)), "writable calendar");
|
|
55
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infaris/calendar-cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Command line interface for Calendar by Infaris: log in once on your device, read your agenda, manage work tasks, and fill the urenstaat from tasks, commits and PRs.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"scripts": {
|
|
22
22
|
"build": "tsc -p tsconfig.json",
|
|
23
23
|
"dev": "tsx src/index.ts",
|
|
24
|
-
"lint": "
|
|
24
|
+
"lint": "eslint \"src/**/*.{ts,tsx}\" --cache --cache-location .cache/eslint --cache-strategy content",
|
|
25
25
|
"typecheck": "tsgo -p tsconfig.json --noEmit",
|
|
26
26
|
"typecheck:legacy": "tsc -p tsconfig.json --noEmit",
|
|
27
27
|
"test": "node --import tsx --test tests/*.test.ts",
|
|
@@ -33,6 +33,8 @@
|
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"@types/node": "^22.0.0",
|
|
35
35
|
"tsx": "^4.20.5",
|
|
36
|
-
"typescript": "^5.6.0"
|
|
36
|
+
"typescript": "^5.6.0",
|
|
37
|
+
"@infaris/eslint-config": "workspace:*",
|
|
38
|
+
"eslint": "^10.8.1"
|
|
37
39
|
}
|
|
38
40
|
}
|