ente-cli 0.4.129 → 0.4.130

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/dist/cli.mjs CHANGED
@@ -28762,7 +28762,7 @@ function parseOperationAttrs(operation, pairs) {
28762
28762
  }
28763
28763
 
28764
28764
  // ente/version.ts
28765
- var VERSION = "0.4.129";
28765
+ var VERSION = "0.4.130";
28766
28766
 
28767
28767
  // ente/branding.ts
28768
28768
  var NPM_REGISTRY = "https://registry.npmjs.org";
@@ -43167,12 +43167,12 @@ function parseDeadline(input2) {
43167
43167
  const second = iso[6] ? Number(iso[6]) : 0;
43168
43168
  validateDate(year, month, day, input2);
43169
43169
  if (hour > 23 || minute > 59 || second > 59) throw new Error(`Invalid time in deadline: '${input2}'.`);
43170
- let offsetMs = 0;
43170
+ let offsetMs2 = 0;
43171
43171
  if (iso[7]) {
43172
43172
  const sign = iso[7] === "-" ? -1 : 1;
43173
- offsetMs = sign * (Number(iso[8]) * 60 + Number(iso[9])) * 6e4;
43173
+ offsetMs2 = sign * (Number(iso[8]) * 60 + Number(iso[9])) * 6e4;
43174
43174
  }
43175
- return Date.UTC(year, month - 1, day, hour, minute, second) - offsetMs;
43175
+ return Date.UTC(year, month - 1, day, hour, minute, second) - offsetMs2;
43176
43176
  }
43177
43177
  const date5 = /^(\d{4})-(\d{2})-(\d{2})(?:\s+(\d{1,2}):(\d{2}))?$/.exec(trimmed);
43178
43178
  if (date5) {
@@ -48130,6 +48130,645 @@ var AGENDA_COMMANDS = [
48130
48130
  AgendaHtmlUpdate
48131
48131
  ];
48132
48132
 
48133
+ // ente/calendar.ts
48134
+ init_server();
48135
+ var calendarRefs = {
48136
+ connections: makeFunctionReference2("calendarExternal:connectionStatusesForAgent"),
48137
+ list: makeFunctionReference2("calendarExternal:listEventsForAgent"),
48138
+ get: makeFunctionReference2("calendarExternal:getEventForAgent"),
48139
+ create: makeFunctionReference2("calendarExternal:createEventForAgent"),
48140
+ update: makeFunctionReference2("calendarExternal:updateEventForAgent"),
48141
+ remove: makeFunctionReference2("calendarExternal:deleteEventForAgent"),
48142
+ meeting: makeFunctionReference2("calendarExternal:ensureMeetingForAgent"),
48143
+ localList: makeFunctionReference2("calendar:listEventsForAgent"),
48144
+ localGet: makeFunctionReference2("calendar:getLocalEventForAgent"),
48145
+ localCreate: makeFunctionReference2("calendar:createLocalEventForAgent"),
48146
+ localUpdate: makeFunctionReference2("calendar:updateLocalEventForAgent"),
48147
+ localDelete: makeFunctionReference2("calendar:deleteLocalEventForAgent")
48148
+ };
48149
+ function formatEventRef(ref) {
48150
+ const e = encodeURIComponent;
48151
+ switch (ref.kind) {
48152
+ case "google":
48153
+ return `google:${e(ref.connectionId)}:${e(ref.calendarId)}:${e(ref.eventId)}`;
48154
+ case "caldav":
48155
+ return `caldav:${e(ref.calendarId)}:${e(ref.eventId)}`;
48156
+ case "local":
48157
+ return `local:${e(ref.eventId)}`;
48158
+ }
48159
+ }
48160
+ function externalEventRef(event) {
48161
+ if (event.provider === "google" && event.connectionId && event.calendarId)
48162
+ return formatEventRef({ kind: "google", connectionId: event.connectionId, calendarId: event.calendarId, eventId: event.eventId });
48163
+ if (event.provider === "caldav" && event.calendarId)
48164
+ return formatEventRef({ kind: "caldav", calendarId: event.calendarId, eventId: event.eventId });
48165
+ return null;
48166
+ }
48167
+ function parseEventRef(value) {
48168
+ const parts = value.split(":");
48169
+ const d = (part) => {
48170
+ if (!part) throw new Error(`Invalid event reference "${value}".`);
48171
+ return decodeURIComponent(part);
48172
+ };
48173
+ if (parts[0] === "google" && parts.length === 4)
48174
+ return { kind: "google", connectionId: d(parts[1]), calendarId: d(parts[2]), eventId: d(parts[3]) };
48175
+ if (parts[0] === "caldav" && parts.length === 3) return { kind: "caldav", calendarId: d(parts[1]), eventId: d(parts[2]) };
48176
+ if (parts[0] === "local" && parts.length === 2) return { kind: "local", eventId: d(parts[1]) };
48177
+ throw new Error(`Invalid event reference "${value}". Use the ref printed by \`ente calendar list\` (google:\u2026, caldav:\u2026 or local:\u2026).`);
48178
+ }
48179
+ var DEFAULT_TIME_ZONE = "Europe/Berlin";
48180
+ var DATE_RE = /^(\d{4})-(\d{2})-(\d{2})$/;
48181
+ var WALL_RE = /^(\d{4})-(\d{2})-(\d{2})[T ](\d{1,2}):(\d{2})(?::(\d{2}))?$/;
48182
+ var ZONED_RE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$/;
48183
+ function assertTimeZone(timeZone) {
48184
+ try {
48185
+ new Intl.DateTimeFormat("en-US", { timeZone }).format(0);
48186
+ } catch {
48187
+ throw new Error(`Unknown time zone "${timeZone}". Use an IANA name such as Europe/Berlin.`);
48188
+ }
48189
+ return timeZone;
48190
+ }
48191
+ function offsetMs(utcMs, timeZone) {
48192
+ const parts = new Intl.DateTimeFormat("en-US", {
48193
+ timeZone,
48194
+ hour12: false,
48195
+ year: "numeric",
48196
+ month: "2-digit",
48197
+ day: "2-digit",
48198
+ hour: "2-digit",
48199
+ minute: "2-digit",
48200
+ second: "2-digit"
48201
+ }).formatToParts(new Date(utcMs));
48202
+ const get2 = (type) => Number(parts.find((part) => part.type === type)?.value ?? 0);
48203
+ const hour = get2("hour") === 24 ? 0 : get2("hour");
48204
+ return Date.UTC(get2("year"), get2("month") - 1, get2("day"), hour, get2("minute"), get2("second")) - utcMs;
48205
+ }
48206
+ function zonedWallTimeToMs({ year, month, day, hour, minute, second = 0 }, timeZone) {
48207
+ const naive = Date.UTC(year, month - 1, day, hour, minute, second);
48208
+ const first = offsetMs(naive, timeZone);
48209
+ let ms = naive - first;
48210
+ const second2 = offsetMs(ms, timeZone);
48211
+ if (second2 !== first) ms = naive - second2;
48212
+ if (ms + offsetMs(ms, timeZone) !== naive)
48213
+ throw new Error(`${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")} ${hour}:${String(minute).padStart(2, "0")} does not exist in ${timeZone} (clock change); pick another time or give an explicit offset.`);
48214
+ return ms;
48215
+ }
48216
+ function checkedDate(year, month, day, raw) {
48217
+ const date5 = new Date(Date.UTC(year, month - 1, day));
48218
+ if (date5.getUTCFullYear() !== year || date5.getUTCMonth() !== month - 1 || date5.getUTCDate() !== day)
48219
+ throw new Error(`Invalid date "${raw}".`);
48220
+ }
48221
+ function parseInstant(raw, timeZone, flag) {
48222
+ const value = raw.trim().replace(/^(\d{4}-\d{2}-\d{2}) (?=\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:\d{2})$)/, "$1T");
48223
+ if (ZONED_RE.test(value)) {
48224
+ const ms = Date.parse(value);
48225
+ if (Number.isFinite(ms)) return ms;
48226
+ }
48227
+ const match = WALL_RE.exec(value);
48228
+ if (match) {
48229
+ const [year, month, day, hour, minute, second] = match.slice(1).map((part) => Number(part ?? 0));
48230
+ checkedDate(year, month, day, raw);
48231
+ if (hour > 23 || minute > 59 || second > 59) throw new Error(`Invalid time in ${flag} "${raw}".`);
48232
+ return zonedWallTimeToMs({ year, month, day, hour, minute, second }, timeZone);
48233
+ }
48234
+ if (DATE_RE.test(value)) throw new Error(`${flag} "${raw}" is a date; add a time (YYYY-MM-DD HH:MM) or use --all-day.`);
48235
+ throw new Error(`Invalid ${flag} "${raw}". Use YYYY-MM-DD HH:MM (in --tz), or ISO 8601 with Z/offset.`);
48236
+ }
48237
+ function parseDay(raw, flag) {
48238
+ const match = DATE_RE.exec(raw.trim());
48239
+ if (!match) throw new Error(`Invalid ${flag} "${raw}" for an all-day event. Use YYYY-MM-DD.`);
48240
+ checkedDate(Number(match[1]), Number(match[2]), Number(match[3]), raw);
48241
+ return raw.trim();
48242
+ }
48243
+ function addDays(day, days) {
48244
+ const [year, month, date5] = day.split("-").map(Number);
48245
+ return new Date(Date.UTC(year, month - 1, date5 + days)).toISOString().slice(0, 10);
48246
+ }
48247
+ function dayToUtcMs(day) {
48248
+ const [year, month, date5] = day.split("-").map(Number);
48249
+ return Date.UTC(year, month - 1, date5);
48250
+ }
48251
+ function todayIn(timeZone) {
48252
+ const parts = new Intl.DateTimeFormat("en-CA", { timeZone, year: "numeric", month: "2-digit", day: "2-digit" }).format(/* @__PURE__ */ new Date());
48253
+ return parts;
48254
+ }
48255
+ function formatInZone(iso, allDay, timeZone) {
48256
+ if (allDay) return iso.slice(0, 10);
48257
+ const ms = Date.parse(iso);
48258
+ if (!Number.isFinite(ms)) return iso;
48259
+ return new Intl.DateTimeFormat("sv-SE", { timeZone, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" }).format(new Date(ms));
48260
+ }
48261
+ function resolveTiming({ start, end, durationMinutes, allDay, timeZone }) {
48262
+ if (end !== void 0 && durationMinutes !== void 0) throw new Error("Use either --end or --duration, not both.");
48263
+ if (allDay) {
48264
+ if (durationMinutes !== void 0) throw new Error("--duration does not apply to all-day events; use --end with the last day.");
48265
+ const startDay = parseDay(start, "--start");
48266
+ const lastDay = end === void 0 ? startDay : parseDay(end, "--end");
48267
+ if (lastDay < startDay) throw new Error("--end must not be before --start.");
48268
+ const endDayExclusive = addDays(lastDay, 1);
48269
+ return { allDay: true, startMs: dayToUtcMs(startDay), endMs: dayToUtcMs(endDayExclusive), startDay, endDayExclusive };
48270
+ }
48271
+ const startMs = parseInstant(start, timeZone, "--start");
48272
+ const endMs = end !== void 0 ? parseInstant(end, timeZone, "--end") : startMs + (durationMinutes ?? 60) * 6e4;
48273
+ if (durationMinutes !== void 0 && (!Number.isInteger(durationMinutes) || durationMinutes <= 0))
48274
+ throw new Error("--duration must be a positive number of minutes.");
48275
+ if (endMs <= startMs) throw new Error("The event must end after it starts.");
48276
+ return { allDay: false, startMs, endMs };
48277
+ }
48278
+ function externalTimes(timing) {
48279
+ return timing.allDay ? { start: timing.startDay, end: timing.endDayExclusive, allDay: true } : { start: new Date(timing.startMs).toISOString(), end: new Date(timing.endMs).toISOString(), allDay: false };
48280
+ }
48281
+ var EMAIL_RE = /^[^\s@,;<>]+@[^\s@,;<>]+\.[^\s@,;<>]+$/;
48282
+ function normalizeAttendees(values) {
48283
+ const emails = values.flatMap((value) => value.split(",")).map((value) => value.trim()).filter(Boolean);
48284
+ for (const email3 of emails) if (!EMAIL_RE.test(email3)) throw new Error(`Invalid attendee email "${email3}".`);
48285
+ return [...new Map(emails.map((email3) => [email3.toLowerCase(), email3])).values()];
48286
+ }
48287
+ function resolveCreateTarget(statuses, { account, calendar, caldav }) {
48288
+ if (caldav !== void 0) {
48289
+ if (account !== void 0 || calendar !== void 0) throw new Error("--caldav cannot be combined with --account or --calendar.");
48290
+ const match = statuses.caldavCalendars.filter((row2) => row2.calendarId === caldav || row2.calendarName.toLowerCase() === caldav.toLowerCase());
48291
+ if (match.length !== 1) throw new Error(match.length === 0 ? `No connected CalDAV calendar "${caldav}". Run \`ente calendar connections\`.` : `CalDAV calendar name "${caldav}" is ambiguous; pass its URL.`);
48292
+ return { kind: "caldav", calendarId: match[0].calendarId, label: `${match[0].calendarName} (CalDAV)` };
48293
+ }
48294
+ const accounts = account === void 0 ? statuses.google : statuses.google.filter((row2) => row2.email.toLowerCase() === account.toLowerCase() || row2.connectionId === account);
48295
+ if (account !== void 0 && accounts.length === 0)
48296
+ throw new Error(`No connected Google account "${account}". Connected: ${statuses.google.map((row2) => row2.email).join(", ") || "none"}.`);
48297
+ if (accounts.length === 0)
48298
+ throw new Error("No Google Calendar is connected. Connect one in ente (Settings \u2192 Calendar), or use --local --space <space>.");
48299
+ const candidates = accounts.flatMap((row2) => row2.calendars.map((cal2) => ({ row: row2, cal: cal2 })));
48300
+ let chosen;
48301
+ if (calendar !== void 0) {
48302
+ chosen = candidates.filter(({ cal: cal2 }) => cal2.calendarId === calendar || cal2.name.toLowerCase() === calendar.toLowerCase());
48303
+ if (chosen.length === 0) throw new Error(`No calendar "${calendar}"${account ? ` in ${account}` : ""}. Run \`ente calendar connections\`.`);
48304
+ } else {
48305
+ chosen = candidates.filter(({ cal: cal2 }) => cal2.defaultWrite);
48306
+ if (chosen.length === 0 && accounts.length === 1) chosen = candidates.filter(({ cal: cal2 }) => cal2.primary);
48307
+ if (chosen.length === 0) throw new Error("No default calendar is set; pass --account and/or --calendar.");
48308
+ }
48309
+ if (chosen.length > 1) throw new Error(`Several calendars match (${chosen.map(({ row: row2, cal: cal2 }) => `${row2.email}: ${cal2.name}`).join("; ")}); pass --account and --calendar.`);
48310
+ const { row, cal } = chosen[0];
48311
+ if (!cal.editable) throw new Error(`Calendar "${cal.name}" in ${row.email} is read-only (${cal.accessRole}).`);
48312
+ return { kind: "google", connectionId: row.connectionId, calendarId: cal.calendarId, label: `${cal.name} (${row.email})` };
48313
+ }
48314
+ function assertSuccess(result, verb) {
48315
+ if (!result.success) {
48316
+ const ref = result.event ? externalEventRef(result.event) : null;
48317
+ throw new Error(`Calendar ${verb} failed: ${result.error}${ref ? ` (event ${ref})` : ""}`);
48318
+ }
48319
+ return result;
48320
+ }
48321
+ async function getConnections(caller) {
48322
+ return await caller.action(calendarRefs.connections, {});
48323
+ }
48324
+ async function getEvent(caller, ref) {
48325
+ if (ref.kind === "local") {
48326
+ const event2 = await caller.query(calendarRefs.localGet, { eventId: ref.eventId });
48327
+ if (!event2) throw new Error(`Local calendar event ${ref.eventId} not found.`);
48328
+ return event2;
48329
+ }
48330
+ const event = await caller.action(calendarRefs.get, ref.kind === "google" ? { provider: "google", connectionId: ref.connectionId, calendarId: ref.calendarId, eventId: ref.eventId } : { provider: "caldav", calendarId: ref.calendarId, eventId: ref.eventId });
48331
+ if (!event) throw new Error(`Calendar event ${formatEventRef(ref)} not found or not readable.`);
48332
+ return event;
48333
+ }
48334
+
48335
+ // ente/commands/calendar.ts
48336
+ var CATEGORY = "Calendar";
48337
+ function isExternal(event) {
48338
+ return "provider" in event;
48339
+ }
48340
+ function eventRef(event) {
48341
+ if (isExternal(event)) return externalEventRef(event) ?? `${event.provider}:${event.eventId}`;
48342
+ return event.localEventId ? formatEventRef({ kind: "local", eventId: event.localEventId }) : event.id;
48343
+ }
48344
+ function meetingUri(event) {
48345
+ if (event.meetingLink) return event.meetingLink;
48346
+ if (isExternal(event)) return event.conference?.uri;
48347
+ return void 0;
48348
+ }
48349
+ function eventLine(event, timeZone) {
48350
+ const when = `${formatInZone(event.start, event.allDay, timeZone)}${event.end ? ` \u2192 ${formatInZone(event.end, event.allDay, timeZone)}` : ""}`;
48351
+ const where = isExternal(event) ? event.provider === "google" ? `${event.calendarName ?? event.calendarId ?? "Google"}${event.accountEmail ? ` <${event.accountEmail}>` : ""}` : `${event.calendarName ?? "CalDAV"}` : event.source === "task" ? "task" : "ente";
48352
+ return `${when} ${event.title} [${where}]
48353
+ ref: ${eventRef(event)}`;
48354
+ }
48355
+ function eventDetails(event, timeZone) {
48356
+ const lines = [eventLine(event, timeZone)];
48357
+ if (event.timeZone) lines.push(` time zone: ${event.timeZone}`);
48358
+ if (event.location) lines.push(` location: ${event.location}`);
48359
+ const uri = meetingUri(event);
48360
+ if (uri) lines.push(` video: ${uri}`);
48361
+ if (isExternal(event) && event.attendees?.length)
48362
+ lines.push(` attendees: ${event.attendees.map((guest) => `${guest.email}${guest.responseStatus ? ` (${guest.responseStatus})` : ""}${guest.organizer ? " [organizer]" : ""}`).join(", ")}`);
48363
+ if (event.recurrence?.length) lines.push(` recurrence: ${event.recurrence.join(" ")}`);
48364
+ if (!isExternal(event)) {
48365
+ lines.push(` space: ${event.spaceId}`);
48366
+ if (event.entityId) lines.push(` entity: ${event.entityId}`);
48367
+ if (event.activityId) lines.push(` activity: ${event.activityId}`);
48368
+ }
48369
+ if (event.href) lines.push(` link: ${event.href}`);
48370
+ if (event.description) lines.push(` description: ${event.description.replace(/\n/g, "\n ")}`);
48371
+ return lines.join("\n");
48372
+ }
48373
+ function parseDuration(raw) {
48374
+ if (raw === void 0) return void 0;
48375
+ const minutes = Number(raw);
48376
+ if (!Number.isInteger(minutes) || minutes <= 0) throw new Error("--duration must be a positive number of minutes.");
48377
+ return minutes;
48378
+ }
48379
+ async function meetingRequest(caller, space3, entities, title4) {
48380
+ if (!space3) throw new Error("--meeting needs --space <name|id> (the space the meeting activity belongs to).");
48381
+ return {
48382
+ spaceId: await resolveSpaceByNameC(caller, space3),
48383
+ entityIds: await resolveEntitiesC(caller, entities),
48384
+ ...title4 ? { title: title4 } : {}
48385
+ };
48386
+ }
48387
+ var CalendarConnectionsCmd = class extends ProfileCommand {
48388
+ static paths = [["calendar", "connections"]];
48389
+ static usage = Command.Usage({
48390
+ category: CATEGORY,
48391
+ description: "Show connected calendar accounts and calendars, and which one `create` writes to by default"
48392
+ });
48393
+ async run() {
48394
+ const data = await getConnections(await resolveCaller());
48395
+ this.emitText(data, () => {
48396
+ const lines = [];
48397
+ for (const account of data.google) {
48398
+ lines.push(`Google ${account.email} (connection ${account.connectionId})`);
48399
+ for (const cal of account.calendars)
48400
+ lines.push(` ${cal.defaultWrite ? "*" : " "} ${cal.name} id=${cal.calendarId} ${cal.accessRole}${cal.editable ? "" : " (read-only)"}${cal.selected ? "" : " (hidden)"}${cal.primary ? " (primary)" : ""}`);
48401
+ }
48402
+ for (const cal of data.caldavCalendars) lines.push(`CalDAV ${cal.calendarName} ${cal.username}@${cal.serverUrl} id=${cal.calendarId}`);
48403
+ if (!lines.length) return "No external calendars connected. Local ente events: `ente calendar create --local --space <space>`.";
48404
+ lines.push("", "* = default target of `ente calendar create` (override with --account/--calendar, --caldav or --local).");
48405
+ return lines.join("\n");
48406
+ });
48407
+ }
48408
+ };
48409
+ var CalendarListCmd = class extends ProfileCommand {
48410
+ static paths = [["calendar", "list"]];
48411
+ static usage = Command.Usage({
48412
+ category: CATEGORY,
48413
+ description: "List events of the connected calendars (and ente events of a space or entity) in a date range",
48414
+ examples: [
48415
+ ["Next 7 days", "ente calendar list"],
48416
+ ["One week, one search term", "ente calendar list --from 2026-11-16 --to 2026-11-22 --query Steuer"],
48417
+ ["Including ente events of a space", "ente calendar list --space Kanzlei --days 14"]
48418
+ ]
48419
+ });
48420
+ from = options_exports.String("--from", { description: "First day YYYY-MM-DD (default: today in --tz)" });
48421
+ to = options_exports.String("--to", { description: "Last day YYYY-MM-DD, inclusive (default: --from + --days \u2212 1)" });
48422
+ days = options_exports.String("--days", { description: "Number of days when --to is absent (default 7)" });
48423
+ query = options_exports.String("--query", { description: "Only events whose title, description or location contain this text" });
48424
+ space = options_exports.String("--space", { description: "Also list ente (local) events and task dates of this space" });
48425
+ entity = options_exports.String("--entity", { description: "Also list ente (local) events and task dates linked to this entity" });
48426
+ tasks = options_exports.Boolean("--tasks", false, { description: "With --space/--entity: include task due dates" });
48427
+ externalOnly = options_exports.Boolean("--external-only", false, { description: "Skip ente events even with --space/--entity" });
48428
+ localOnly = options_exports.Boolean("--local-only", false, { description: "With --space/--entity: only ente events (works with keys of shared agents)" });
48429
+ max = options_exports.String("--max", { description: "Maximum events per external calendar page (1\u2013250)" });
48430
+ tz = options_exports.String("--tz", DEFAULT_TIME_ZONE, { description: "Time zone for bare dates and output" });
48431
+ async run() {
48432
+ const timeZone = assertTimeZone(this.tz);
48433
+ if (this.space && this.entity) throw new Error("Use either --space or --entity, not both.");
48434
+ const fromDay = this.from === void 0 ? todayIn(timeZone) : parseDay(this.from, "--from");
48435
+ const days = this.days === void 0 ? 7 : Number(this.days);
48436
+ if (!Number.isInteger(days) || days <= 0) throw new Error("--days must be a positive integer.");
48437
+ const toDay = this.to === void 0 ? addDays(fromDay, days - 1) : parseDay(this.to, "--to");
48438
+ if (toDay < fromDay) throw new Error("--to must not be before --from.");
48439
+ const endExclusive = addDays(toDay, 1);
48440
+ const max = this.max === void 0 ? void 0 : Number(this.max);
48441
+ if (max !== void 0 && (!Number.isInteger(max) || max < 1 || max > 250)) throw new Error("--max must be 1\u2013250.");
48442
+ if (this.localOnly && this.externalOnly) throw new Error("Use either --local-only or --external-only.");
48443
+ if (this.localOnly && !this.space && !this.entity) throw new Error("--local-only needs --space or --entity.");
48444
+ const caller = await resolveCaller();
48445
+ const external = this.localOnly ? { events: [], errors: [] } : await caller.action(calendarRefs.list, {
48446
+ timeMin: new Date(resolveTiming({ start: `${fromDay} 00:00`, allDay: false, timeZone }).startMs).toISOString(),
48447
+ timeMax: new Date(resolveTiming({ start: `${endExclusive} 00:00`, allDay: false, timeZone }).startMs).toISOString(),
48448
+ timeZone,
48449
+ ...max === void 0 ? {} : { maxResults: max },
48450
+ ...this.query ? { query: this.query } : {}
48451
+ });
48452
+ let local = [];
48453
+ if ((this.space || this.entity) && !this.externalOnly) {
48454
+ const scope = this.space ? { kind: "dashboard", spaceId: await resolveSpaceByNameC(caller, this.space) } : { kind: "entity", entityId: (await resolveEntitiesC(caller, [this.entity]))[0] };
48455
+ const needle = this.query?.toLocaleLowerCase();
48456
+ local = (await caller.query(calendarRefs.localList, { scope, start: fromDay, end: endExclusive })).filter((event) => event.source !== "google" && (this.tasks || event.source !== "task")).filter((event) => !needle || [event.title, event.description, event.location].some((value) => value?.toLocaleLowerCase().includes(needle)));
48457
+ }
48458
+ const events = [...external.events, ...local].sort((a, b) => Date.parse(a.start) - Date.parse(b.start) || a.title.localeCompare(b.title));
48459
+ this.emitText({ from: fromDay, to: toDay, timeZone, events: events.map((event) => ({ ref: eventRef(event), ...event })), errors: external.errors }, () => [
48460
+ ...events.length ? events.map((event) => eventLine(event, timeZone)) : [`No events ${fromDay} \u2026 ${toDay}.`],
48461
+ ...external.errors.map((error62) => `warning (${error62.provider}): ${error62.message}`)
48462
+ ].join("\n"));
48463
+ return external.errors.length && !external.events.length ? 1 : void 0;
48464
+ }
48465
+ };
48466
+ var CalendarGetCmd = class extends ProfileCommand {
48467
+ static paths = [["calendar", "get"]];
48468
+ static usage = Command.Usage({ category: CATEGORY, description: "Show one event (attendees, video link, recurrence) by its ref from `ente calendar list`" });
48469
+ ref = options_exports.String({ required: true, name: "ref" });
48470
+ tz = options_exports.String("--tz", DEFAULT_TIME_ZONE, { description: "Time zone for output" });
48471
+ async run() {
48472
+ const timeZone = assertTimeZone(this.tz);
48473
+ const event = await getEvent(await resolveCaller(), parseEventRef(this.ref));
48474
+ this.emitText({ ref: eventRef(event), ...event }, () => eventDetails(event, timeZone));
48475
+ }
48476
+ };
48477
+ var EventFieldsCommand = class extends ProfileCommand {
48478
+ title = options_exports.String("--title", { description: "Event title" });
48479
+ start = options_exports.String("--start", { description: "Start: YYYY-MM-DD HH:MM in --tz, ISO 8601 with offset, or YYYY-MM-DD with --all-day" });
48480
+ end = options_exports.String("--end", { description: "End (same formats); for --all-day the last day, inclusive" });
48481
+ duration = options_exports.String("--duration", { description: "Length in minutes instead of --end (timed events)" });
48482
+ tz = options_exports.String("--tz", DEFAULT_TIME_ZONE, { description: "IANA time zone of bare times and of the event" });
48483
+ location = options_exports.String("--location", { description: "Location" });
48484
+ description = options_exports.String("--description", { description: "Description (plain text)" });
48485
+ attendees = options_exports.Array("--attendee", [], { description: "Guest email; repeatable or comma-separated (Google only)" });
48486
+ sendInvites = options_exports.Boolean("--send-invites", false, {
48487
+ description: "Mail guests (invitation / update / cancellation). Default: no mail to anyone"
48488
+ });
48489
+ meet = options_exports.Boolean("--meet", false, { description: "Add a Google Meet video conference (Google only)" });
48490
+ recurrence = options_exports.Array("--recurrence", [], { description: "RFC 5545 line, e.g. RRULE:FREQ=WEEKLY;COUNT=4; repeatable" });
48491
+ color = options_exports.String("--color", { description: "Google colorId (1\u201311) or, for local events, a color name" });
48492
+ meetingLink = options_exports.String("--meeting-link", { description: "Video link stored on a local ente event (external: use --meet or --location)" });
48493
+ };
48494
+ var CalendarCreateCmd = class extends EventFieldsCommand {
48495
+ static paths = [["calendar", "create"]];
48496
+ static usage = Command.Usage({
48497
+ category: CATEGORY,
48498
+ description: "Create an event in a connected calendar (default target: see `ente calendar connections`) or as a local ente event",
48499
+ details: `
48500
+ Target: the default Google calendar unless --account/--calendar, --caldav or --local choose another.
48501
+ Guests: --attendee adds them to the event; they are only mailed with --send-invites.
48502
+ Video: --meet creates a Google Meet link. Reminders follow the calendar's defaults.
48503
+ Graph: --meeting --space S [--entity E \u2026] creates the event's meeting activity in ente;
48504
+ local events take --space plus at most one --entity and an optional --activity.
48505
+ `,
48506
+ examples: [
48507
+ ["Meeting in the default calendar, no mail", "ente calendar create --title 'Steuer Q4' --start '2026-11-20 14:00' --duration 45 --meet"],
48508
+ ["In a specific account, with guests and invitations", "ente calendar create --account me@example.org --title Kickoff --start '2026-11-24 10:00' --attendee a@example.org --attendee b@example.org --send-invites --meet"],
48509
+ ["All-day, two days", "ente calendar create --title Messe --start 2026-12-01 --end 2026-12-02 --all-day"],
48510
+ ["Local ente event linked to an entity", "ente calendar create --local --space Kanzlei --entity 'Muster GmbH' --title Frist --start '2026-11-30 09:00'"],
48511
+ ["With meeting activity in the graph", "ente calendar create --title 'Jour fixe' --start '2026-11-21 09:00' --meeting --space Kanzlei --entity 'Muster GmbH'"]
48512
+ ]
48513
+ });
48514
+ allDay = options_exports.Boolean("--all-day", false, { description: "All-day event; --start/--end are days" });
48515
+ account = options_exports.String("--account", { description: "Google account email (or connection id) to write to" });
48516
+ calendar = options_exports.String("--calendar", { description: "Google calendar id or name (default: the account's default calendar)" });
48517
+ caldav = options_exports.String("--caldav", { description: "CalDAV calendar URL or name" });
48518
+ local = options_exports.Boolean("--local", false, { description: "Create a local ente event (needs --space)" });
48519
+ space = options_exports.String("--space", { description: "Space of a local event, or of the --meeting activity" });
48520
+ entities = options_exports.Array("--entity", [], { description: "Entity name or id; repeatable (local events: at most one)" });
48521
+ activity = options_exports.String("--activity", { description: "Local events: link an existing activity id" });
48522
+ meeting = options_exports.Boolean("--meeting", false, { description: "External events: create the meeting activity in ente (needs --space)" });
48523
+ async run() {
48524
+ if (!this.title?.trim()) throw new Error("--title is required.");
48525
+ if (!this.start) throw new Error("--start is required.");
48526
+ const timeZone = assertTimeZone(this.tz);
48527
+ const timing = resolveTiming({ start: this.start, end: this.end, durationMinutes: parseDuration(this.duration), allDay: this.allDay, timeZone });
48528
+ const attendees = normalizeAttendees(this.attendees);
48529
+ if (this.sendInvites && !attendees.length) throw new Error("--send-invites needs at least one --attendee.");
48530
+ const caller = await resolveCaller();
48531
+ if (this.local) {
48532
+ if (this.account || this.calendar || this.caldav) throw new Error("--local cannot be combined with --account, --calendar or --caldav.");
48533
+ if (attendees.length || this.sendInvites || this.meet) throw new Error("Local ente events have no guests or Google Meet; use a Google calendar for those.");
48534
+ if (this.meeting) throw new Error("--meeting applies to external events; link a local event with --activity.");
48535
+ if (!this.space) throw new Error("--local needs --space <name|id>.");
48536
+ if (this.entities.length > 1) throw new Error("A local event links at most one --entity.");
48537
+ const input2 = {
48538
+ title: this.title.trim(),
48539
+ startMs: timing.startMs,
48540
+ endMs: timing.endMs,
48541
+ allDay: timing.allDay,
48542
+ timeZone: timing.allDay ? null : timeZone,
48543
+ spaceId: await resolveSpaceByNameC(caller, this.space),
48544
+ ...this.entities.length ? { entityId: (await resolveEntitiesC(caller, this.entities))[0] } : {},
48545
+ ...this.activity ? { activityId: this.activity } : {},
48546
+ ...this.location ? { location: this.location } : {},
48547
+ ...this.description ? { description: this.description } : {},
48548
+ ...this.meetingLink ? { meetingLink: this.meetingLink } : {},
48549
+ ...this.color ? { color: this.color } : {},
48550
+ ...this.recurrence.length ? { recurrence: this.recurrence } : {}
48551
+ };
48552
+ const event2 = await caller.mutation(calendarRefs.localCreate, input2);
48553
+ this.emitText({ ref: eventRef(event2), event: event2 }, () => `Created local event
48554
+ ${eventDetails(event2, timeZone)}`);
48555
+ return;
48556
+ }
48557
+ if (this.activity) throw new Error("--activity links local events; for external events use --meeting.");
48558
+ if (this.meetingLink) throw new Error("--meeting-link is for local events; use --meet or --location for external ones.");
48559
+ if (!this.meeting && (this.space || this.entities.length)) throw new Error("--space/--entity on an external event need --meeting (create the meeting activity).");
48560
+ const target3 = resolveCreateTarget(await getConnections(caller), { account: this.account, calendar: this.calendar, caldav: this.caldav });
48561
+ if (target3.kind === "local") throw new Error("Unexpected local target.");
48562
+ const meeting = this.meeting ? await meetingRequest(caller, this.space, this.entities, this.title.trim()) : void 0;
48563
+ const result = await caller.action(calendarRefs.create, {
48564
+ provider: target3.kind,
48565
+ ...target3.kind === "google" ? { connectionId: target3.connectionId } : {},
48566
+ calendarId: target3.calendarId,
48567
+ title: this.title.trim(),
48568
+ ...externalTimes(timing),
48569
+ ...timing.allDay ? {} : { timeZone },
48570
+ ...this.location ? { location: this.location } : {},
48571
+ ...this.description ? { description: this.description } : {},
48572
+ ...attendees.length ? { attendees } : {},
48573
+ ...this.meet ? { createConference: true } : {},
48574
+ ...this.recurrence.length ? { recurrence: this.recurrence } : {},
48575
+ ...this.color ? { colorId: this.color } : {},
48576
+ notifyAttendees: this.sendInvites,
48577
+ ...meeting ? { meeting } : {}
48578
+ });
48579
+ const { event, meeting: linked } = assertSuccess(result, "create");
48580
+ this.emitText({ ref: eventRef(event), event, ...linked ? { meeting: linked } : {}, invitationsSent: this.sendInvites && attendees.length > 0 }, () => [
48581
+ `Created in ${target3.label}`,
48582
+ eventDetails(event, timeZone),
48583
+ ...attendees.length ? [this.sendInvites ? " invitations: sent" : " invitations: not sent (add --send-invites to mail guests)"] : [],
48584
+ ...linked ? [` meeting activity: ${linked.meetingActivityId}${linked.created ? " (created)" : " (existing)"}`] : []
48585
+ ].join("\n"));
48586
+ }
48587
+ };
48588
+ var CalendarUpdateCmd = class extends EventFieldsCommand {
48589
+ static paths = [["calendar", "update"]];
48590
+ static usage = Command.Usage({
48591
+ category: CATEGORY,
48592
+ description: "Change an event by its ref; only the given fields change",
48593
+ details: `
48594
+ --attendee replaces the whole guest list; --clear-attendees removes all guests.
48595
+ Guests are mailed about the change only with --send-invites.
48596
+ Times: give --start (and optionally --end/--duration); a new --start alone keeps the event's length.
48597
+ `,
48598
+ examples: [
48599
+ ["Move by an hour, no mail", "ente calendar update google:\u2026 --start '2026-11-20 15:00'"],
48600
+ ["Add a guest and invite", "ente calendar update google:\u2026 --attendee a@example.org --attendee new@example.org --send-invites"]
48601
+ ]
48602
+ });
48603
+ ref = options_exports.String({ required: true, name: "ref" });
48604
+ allDay = options_exports.Boolean("--all-day", { description: "Make the event all-day (--no-all-day: timed)" });
48605
+ clearAttendees = options_exports.Boolean("--clear-attendees", false, { description: "Remove all guests" });
48606
+ series = options_exports.Boolean("--series", false, { description: "Local recurring events: confirm that the change applies to the whole series" });
48607
+ clearRecurrence = options_exports.Boolean("--clear-recurrence", false, { description: "Local events: make the event non-recurring" });
48608
+ clearMeetingLink = options_exports.Boolean("--clear-meeting-link", false, { description: "Local events: remove the stored meeting link" });
48609
+ moveToCalendar = options_exports.String("--move-to-calendar", { description: "Google: move to another calendar id (same or --move-to-account)" });
48610
+ moveToAccount = options_exports.String("--move-to-account", { description: "Google: connection id of the destination calendar" });
48611
+ space = options_exports.String("--space", { description: "Local events: move to this space" });
48612
+ entity = options_exports.String("--entity", { description: "Local events: link this entity ('' to unlink)" });
48613
+ activity = options_exports.String("--activity", { description: "Local events: link this activity id ('' to unlink)" });
48614
+ async run() {
48615
+ const timeZone = assertTimeZone(this.tz);
48616
+ const ref = parseEventRef(this.ref);
48617
+ const caller = await resolveCaller();
48618
+ if (this.clearAttendees && this.attendees.length) throw new Error("Use either --attendee or --clear-attendees.");
48619
+ const attendees = this.clearAttendees ? [] : this.attendees.length ? normalizeAttendees(this.attendees) : void 0;
48620
+ const current = await getEvent(caller, ref);
48621
+ const timeFlags = this.start !== void 0 || this.end !== void 0 || this.duration !== void 0 || this.allDay !== void 0;
48622
+ let timing;
48623
+ if (timeFlags) {
48624
+ const allDay = this.allDay ?? current.allDay;
48625
+ if (allDay !== current.allDay && this.start === void 0) throw new Error("Changing --all-day needs a new --start.");
48626
+ const start = this.start ?? (allDay ? current.start.slice(0, 10) : current.start);
48627
+ let end = this.end;
48628
+ let duration3 = parseDuration(this.duration);
48629
+ if (end === void 0 && duration3 === void 0 && current.end) {
48630
+ if (allDay) {
48631
+ const spanDays = Math.max(1, (dayToUtcMs(current.end.slice(0, 10)) - dayToUtcMs(current.start.slice(0, 10))) / 864e5);
48632
+ end = addDays(parseDay(start, "--start"), spanDays - 1);
48633
+ } else if (!current.allDay) {
48634
+ duration3 = Math.round((Date.parse(current.end) - Date.parse(current.start)) / 6e4);
48635
+ }
48636
+ }
48637
+ timing = resolveTiming({ start, end, durationMinutes: duration3, allDay, timeZone });
48638
+ }
48639
+ if (ref.kind === "local") {
48640
+ if (isExternal(current)) throw new Error("Unexpected external event for a local ref.");
48641
+ if (attendees !== void 0 || this.sendInvites || this.meet || this.moveToCalendar || this.moveToAccount)
48642
+ throw new Error("Local ente events have no guests, Google Meet or calendar moves.");
48643
+ if (current.recurrence?.length && !this.series)
48644
+ throw new Error("This local event repeats; a change applies to the whole series (a new --start moves the series start). Repeat with --series to confirm.");
48645
+ if (this.clearRecurrence && this.recurrence.length) throw new Error("Use either --recurrence or --clear-recurrence.");
48646
+ const startMs = timing?.startMs ?? (current.allDay ? dayToUtcMs(current.seriesStart?.slice(0, 10) ?? current.start.slice(0, 10)) : Date.parse(current.seriesStart ?? current.start));
48647
+ const currentEnd = current.seriesEnd ?? current.end;
48648
+ const endMs = timing?.endMs ?? (currentEnd ? current.allDay ? dayToUtcMs(currentEnd.slice(0, 10)) : Date.parse(currentEnd) : null);
48649
+ const pick2 = (flag, existing) => flag === void 0 ? existing ?? null : flag || null;
48650
+ const input2 = {
48651
+ eventId: ref.eventId,
48652
+ title: this.title?.trim() || current.title,
48653
+ startMs,
48654
+ endMs,
48655
+ allDay: timing?.allDay ?? current.allDay,
48656
+ timeZone: timing?.allDay ?? current.allDay ? null : this.tz !== DEFAULT_TIME_ZONE || timing ? timeZone : current.timeZone ?? null,
48657
+ location: pick2(this.location, current.location),
48658
+ description: pick2(this.description, current.description),
48659
+ href: current.href ?? null,
48660
+ meetingLink: this.clearMeetingLink ? null : pick2(this.meetingLink, current.meetingLink),
48661
+ color: pick2(this.color, current.color),
48662
+ recurrence: this.clearRecurrence ? null : this.recurrence.length ? this.recurrence : current.recurrence ?? null,
48663
+ spaceId: this.space ? await resolveSpaceByNameC(caller, this.space) : current.spaceId,
48664
+ entityId: this.entity === void 0 ? current.entityId ?? null : this.entity ? (await resolveEntitiesC(caller, [this.entity]))[0] : null,
48665
+ activityId: pick2(this.activity, current.activityId)
48666
+ };
48667
+ const event2 = await caller.mutation(calendarRefs.localUpdate, input2);
48668
+ this.emitText({ ref: eventRef(event2), event: event2 }, () => `Updated local event
48669
+ ${eventDetails(event2, timeZone)}`);
48670
+ return;
48671
+ }
48672
+ if (this.space || this.entity !== void 0 || this.activity !== void 0 || this.meetingLink || this.clearMeetingLink)
48673
+ throw new Error("--space/--entity/--activity/--meeting-link/--clear-meeting-link apply to local events; use `ente calendar link` for a meeting activity.");
48674
+ if (this.sendInvites && !(attendees?.length || isExternal(current) && current.attendees?.length))
48675
+ throw new Error("--send-invites needs guests on the event.");
48676
+ const patch2 = {
48677
+ ...this.title?.trim() ? { title: this.title.trim() } : {},
48678
+ ...timing ? { ...externalTimes(timing), ...timing.allDay ? {} : { timeZone } } : {},
48679
+ ...this.location !== void 0 ? { location: this.location } : {},
48680
+ ...this.description !== void 0 ? { description: this.description } : {},
48681
+ ...attendees !== void 0 ? { attendees } : {},
48682
+ ...this.meet ? { createConference: true } : {},
48683
+ ...this.recurrence.length ? { recurrence: this.recurrence } : {},
48684
+ ...this.color !== void 0 ? { colorId: this.color || null } : {}
48685
+ };
48686
+ const move = this.moveToCalendar || this.moveToAccount;
48687
+ if (!Object.keys(patch2).length && !move) throw new Error("Nothing to change; pass at least one field (--send-invites only mails guests about a change).");
48688
+ if (this.moveToAccount && !this.moveToCalendar) throw new Error("--move-to-account needs --move-to-calendar.");
48689
+ const result = await caller.action(calendarRefs.update, {
48690
+ provider: ref.kind,
48691
+ ...ref.kind === "google" ? { connectionId: ref.connectionId } : {},
48692
+ calendarId: ref.calendarId,
48693
+ eventId: ref.eventId,
48694
+ ...this.moveToCalendar ? { destinationCalendarId: this.moveToCalendar } : {},
48695
+ ...this.moveToAccount ? { destinationConnectionId: this.moveToAccount } : {},
48696
+ ...patch2,
48697
+ notifyAttendees: this.sendInvites
48698
+ });
48699
+ const { event } = assertSuccess(result, "update");
48700
+ this.emitText({ ref: eventRef(event), event, guestsNotified: this.sendInvites }, () => `Updated${this.sendInvites ? " (guests notified)" : " (no mail sent)"}
48701
+ ${eventDetails(event, timeZone)}`);
48702
+ }
48703
+ };
48704
+ var CalendarDeleteCmd = class extends ProfileCommand {
48705
+ static paths = [["calendar", "delete"]];
48706
+ static usage = Command.Usage({
48707
+ category: CATEGORY,
48708
+ description: "Delete an event by its ref; guests get a cancellation mail only with --send-invites"
48709
+ });
48710
+ ref = options_exports.String({ required: true, name: "ref" });
48711
+ sendInvites = options_exports.Boolean("--send-invites", false, { description: "Mail guests a cancellation" });
48712
+ series = options_exports.Boolean("--series", false, { description: "Local recurring events: confirm deleting the whole series" });
48713
+ async run() {
48714
+ const ref = parseEventRef(this.ref);
48715
+ const caller = await resolveCaller();
48716
+ if (ref.kind === "local") {
48717
+ if (this.sendInvites) throw new Error("Local ente events have no guests.");
48718
+ const current = await getEvent(caller, ref);
48719
+ if (current.recurrence?.length && !this.series)
48720
+ throw new Error("This local event repeats; delete removes the whole series. Repeat with --series to confirm.");
48721
+ await caller.mutation(calendarRefs.localDelete, { eventId: ref.eventId });
48722
+ this.emitText({ deleted: formatEventRef(ref) }, () => `Deleted ${formatEventRef(ref)}`);
48723
+ return;
48724
+ }
48725
+ const result = await caller.action(calendarRefs.remove, {
48726
+ provider: ref.kind,
48727
+ ...ref.kind === "google" ? { connectionId: ref.connectionId } : {},
48728
+ calendarId: ref.calendarId,
48729
+ eventId: ref.eventId,
48730
+ notifyAttendees: this.sendInvites
48731
+ });
48732
+ if (!result.success) throw new Error(`Calendar delete failed: ${result.error}`);
48733
+ this.emitText({ deleted: formatEventRef(ref), guestsNotified: this.sendInvites }, () => `Deleted ${formatEventRef(ref)}${this.sendInvites ? " (guests notified)" : " (no mail sent)"}`);
48734
+ }
48735
+ };
48736
+ var CalendarLinkCmd = class extends ProfileCommand {
48737
+ static paths = [["calendar", "link"]];
48738
+ static usage = Command.Usage({
48739
+ category: CATEGORY,
48740
+ description: "Create (or find) the ente meeting activity of an external event and link it to entities",
48741
+ examples: [["Link to a person and an organisation", "ente calendar link google:\u2026 --space Kanzlei --entity 'Anna Muster' --entity 'Muster GmbH'"]]
48742
+ });
48743
+ ref = options_exports.String({ required: true, name: "ref" });
48744
+ space = options_exports.String("--space", { required: true, description: "Space of the meeting activity" });
48745
+ entities = options_exports.Array("--entity", [], { description: "Entity name or id; repeatable" });
48746
+ title = options_exports.String("--title", { description: "Meeting title (default: the event title)" });
48747
+ async run() {
48748
+ const ref = parseEventRef(this.ref);
48749
+ if (ref.kind === "local") throw new Error("Local events link an activity directly: `ente calendar update local:\u2026 --activity <id>`.");
48750
+ const caller = await resolveCaller();
48751
+ const meeting = await meetingRequest(caller, this.space, this.entities, this.title);
48752
+ const result = await caller.action(calendarRefs.meeting, {
48753
+ provider: ref.kind,
48754
+ ...ref.kind === "google" ? { connectionId: ref.connectionId } : {},
48755
+ calendarId: ref.calendarId,
48756
+ eventId: ref.eventId,
48757
+ meeting
48758
+ });
48759
+ this.emitText(result, () => `Meeting activity ${result.meetingActivityId}${result.created ? " created" : " already existed"}`);
48760
+ }
48761
+ };
48762
+ var CALENDAR_COMMANDS = [
48763
+ CalendarConnectionsCmd,
48764
+ CalendarListCmd,
48765
+ CalendarGetCmd,
48766
+ CalendarCreateCmd,
48767
+ CalendarUpdateCmd,
48768
+ CalendarDeleteCmd,
48769
+ CalendarLinkCmd
48770
+ ];
48771
+
48133
48772
  // ente/commands/feedback.ts
48134
48773
  init_server();
48135
48774
 
@@ -50994,6 +51633,7 @@ for (const Cmd of [
50994
51633
  ...RECORDING_PIPELINE_COMMANDS,
50995
51634
  ...AGENT_COMMANDS,
50996
51635
  ...AGENDA_COMMANDS,
51636
+ ...CALENDAR_COMMANDS,
50997
51637
  ...FEEDBACK_COMMANDS,
50998
51638
  ...GUIDE_COMMANDS,
50999
51639
  ...CANVAS_COMMANDS,