@ncukondo/gcal-cli 0.1.4 → 0.1.5
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/index.js +48 -7
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -587718,7 +587718,7 @@ function errorCodeToExitCode(code) {
|
|
|
587718
587718
|
// package.json
|
|
587719
587719
|
var package_default = {
|
|
587720
587720
|
name: "@ncukondo/gcal-cli",
|
|
587721
|
-
version: "0.1.
|
|
587721
|
+
version: "0.1.5",
|
|
587722
587722
|
type: "module",
|
|
587723
587723
|
exports: {
|
|
587724
587724
|
".": "./dist/index.js"
|
|
@@ -591832,6 +591832,7 @@ async function handleUpdate(opts) {
|
|
|
591832
591832
|
}
|
|
591833
591833
|
function createUpdateCommand() {
|
|
591834
591834
|
const cmd = new Command("update").description("Update an existing event").argument("<event-id>", "Event ID to update");
|
|
591835
|
+
cmd.option("-c, --calendar <id>", "Calendar ID");
|
|
591835
591836
|
cmd.option("-t, --title <title>", "New title");
|
|
591836
591837
|
cmd.option("-s, --start <datetime>", "New start datetime");
|
|
591837
591838
|
cmd.option("-e, --end <datetime>", "New end datetime");
|
|
@@ -592186,6 +592187,30 @@ function handleError2(error, format3) {
|
|
|
592186
592187
|
process.exit(errorCodeToExitCode(errorCode));
|
|
592187
592188
|
}
|
|
592188
592189
|
|
|
592190
|
+
// src/lib/resolve-calendar.ts
|
|
592191
|
+
async function resolveEventCalendar(api2, eventId, calendars) {
|
|
592192
|
+
const results = await Promise.all(calendars.map(async (cal) => {
|
|
592193
|
+
try {
|
|
592194
|
+
await getEvent(api2, cal.id, cal.name, eventId);
|
|
592195
|
+
return { id: cal.id, name: cal.name };
|
|
592196
|
+
} catch (error) {
|
|
592197
|
+
if (error instanceof ApiError && error.code === "NOT_FOUND") {
|
|
592198
|
+
return null;
|
|
592199
|
+
}
|
|
592200
|
+
throw error;
|
|
592201
|
+
}
|
|
592202
|
+
}));
|
|
592203
|
+
const found = results.filter((r) => r !== null);
|
|
592204
|
+
if (found.length === 0) {
|
|
592205
|
+
throw new ApiError("NOT_FOUND", `Event "${eventId}" not found in any enabled calendar`);
|
|
592206
|
+
}
|
|
592207
|
+
if (found.length > 1) {
|
|
592208
|
+
const calList = found.map((c) => `${c.name} (${c.id})`).join(", ");
|
|
592209
|
+
throw new ApiError("INVALID_ARGS", `Event "${eventId}" found in multiple calendars: ${calList}. Specify -c <calendar-id>.`);
|
|
592210
|
+
}
|
|
592211
|
+
return found[0];
|
|
592212
|
+
}
|
|
592213
|
+
|
|
592189
592214
|
// src/commands/index.ts
|
|
592190
592215
|
function registerCommands(program2) {
|
|
592191
592216
|
const authCmd = createAuthCommand();
|
|
@@ -592319,8 +592344,9 @@ ${url}`);
|
|
|
592319
592344
|
const found = config2.calendars.find((c) => c.id === calendarId);
|
|
592320
592345
|
cal = found ? { id: found.id, name: found.name } : { id: calendarId, name: calendarId };
|
|
592321
592346
|
} else {
|
|
592322
|
-
const
|
|
592323
|
-
|
|
592347
|
+
const calendars = selectCalendars(undefined, config2);
|
|
592348
|
+
const resolved = await resolveEventCalendar(api2, showCmd.args[0], calendars);
|
|
592349
|
+
cal = resolved;
|
|
592324
592350
|
}
|
|
592325
592351
|
const timezone = resolveTimezone(globalOpts.timezone, config2.timezone);
|
|
592326
592352
|
const result = await handleShow({
|
|
@@ -592348,8 +592374,15 @@ ${url}`);
|
|
|
592348
592374
|
const auth = await getAuthenticatedClient(fsAdapter);
|
|
592349
592375
|
const calendarApi = import_googleapis2.google.calendar({ version: "v3", auth });
|
|
592350
592376
|
const api2 = createGoogleCalendarApi(calendarApi);
|
|
592351
|
-
|
|
592352
|
-
|
|
592377
|
+
let resolvedCalendarId;
|
|
592378
|
+
if (deleteOpts.calendar || globalOpts.calendar.length > 0) {
|
|
592379
|
+
const calendars = selectCalendars(deleteOpts.calendar ? [deleteOpts.calendar] : globalOpts.calendar, config2);
|
|
592380
|
+
resolvedCalendarId = calendars[0]?.id ?? "primary";
|
|
592381
|
+
} else {
|
|
592382
|
+
const calendars = selectCalendars(undefined, config2);
|
|
592383
|
+
const resolved = await resolveEventCalendar(api2, eventId, calendars);
|
|
592384
|
+
resolvedCalendarId = resolved.id;
|
|
592385
|
+
}
|
|
592353
592386
|
const result = await handleDelete({
|
|
592354
592387
|
api: api2,
|
|
592355
592388
|
eventId,
|
|
@@ -592459,8 +592492,16 @@ ${authUrl}`);
|
|
|
592459
592492
|
const calendar = import_googleapis2.google.calendar({ version: "v3", auth: oauth2Client });
|
|
592460
592493
|
const api2 = createGoogleCalendarApi(calendar);
|
|
592461
592494
|
const timezone = resolveTimezone(globalOpts.timezone, config2.timezone);
|
|
592462
|
-
const
|
|
592463
|
-
|
|
592495
|
+
const updateOpsCalendar = updateOpts.calendar;
|
|
592496
|
+
let cal;
|
|
592497
|
+
if (updateOpsCalendar || globalOpts.calendar.length > 0) {
|
|
592498
|
+
const calendars = selectCalendars(updateOpsCalendar ? [updateOpsCalendar] : globalOpts.calendar, config2);
|
|
592499
|
+
cal = calendars[0];
|
|
592500
|
+
} else {
|
|
592501
|
+
const calendars = selectCalendars(undefined, config2);
|
|
592502
|
+
const resolved = await resolveEventCalendar(api2, eventId, calendars);
|
|
592503
|
+
cal = resolved;
|
|
592504
|
+
}
|
|
592464
592505
|
const result = await handleUpdate({
|
|
592465
592506
|
api: api2,
|
|
592466
592507
|
eventId,
|