Skip to content

Commit 09f15cf

Browse files
committed
Fix: Add fallback for missing updateEventFields in Docker
- Added manual iCal manipulation as fallback when tsdav.updateEventFields is not available - Uses ICAL.js to parse and modify iCal data directly - Detects if tsdav function is available and uses appropriate method - Resolves 'tsdavUpdateEventFields is not a function' error in Docker environments - Maintains compatibility with both local development and Docker production The issue was that tsdav.updateEventFields is undefined in Docker production builds, even though it works locally. This fallback ensures the function works everywhere.
1 parent 54bd0ae commit 09f15cf

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

src/tools/calendar/update-event-fields.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,49 @@ import { tsdavManager } from '../../tsdav-client.js';
22
import { validateInput } from '../../validation.js';
33
import { formatSuccess, formatError } from '../../formatters.js';
44
import { z } from 'zod';
5+
import ICAL from 'ical.js';
56
// Import using namespace import for maximum CommonJS/ESM compatibility
67
import * as tsdavAll from 'tsdav';
78
// Access as property - works in both ESM (named export) and CJS (exports.xxx)
89
const tsdavUpdateEventFields = tsdavAll.updateEventFields;
910

11+
/**
12+
* Manual iCal field update function as fallback
13+
* Updates specific fields in an iCal string when tsdav's updateEventFields is not available
14+
*/
15+
function manualUpdateEventFields(calendarObject, fields) {
16+
const jcalData = ICAL.parse(calendarObject.data);
17+
const comp = new ICAL.Component(jcalData);
18+
const vevent = comp.getFirstSubcomponent('vevent');
19+
20+
if (!vevent) {
21+
throw new Error('No VEVENT component found in calendar object');
22+
}
23+
24+
const modified = [];
25+
const warnings = [];
26+
27+
// Update fields
28+
if (fields.summary !== undefined) {
29+
vevent.updatePropertyWithValue('summary', fields.summary);
30+
modified.push('summary');
31+
}
32+
33+
if (fields.description !== undefined) {
34+
vevent.updatePropertyWithValue('description', fields.description);
35+
modified.push('description');
36+
}
37+
38+
// Convert back to iCal string
39+
const updatedData = comp.toString();
40+
41+
return {
42+
data: updatedData,
43+
modified,
44+
warnings
45+
};
46+
}
47+
1048
/**
1149
* Schema for field-based event updates
1250
* Currently supports MVP fields from tsdav v2.2.0: SUMMARY and DESCRIPTION
@@ -94,8 +132,15 @@ export const updateEventFields = {
94132
}
95133
}
96134

97-
// Step 3: Use tsdav's native updateEventFields function
98-
const result = tsdavUpdateEventFields(calendarObject, tsdavFields);
135+
// Step 3: Use tsdav's native updateEventFields function or fallback to manual implementation
136+
let result;
137+
if (typeof tsdavUpdateEventFields === 'function') {
138+
// Use tsdav's native function if available
139+
result = tsdavUpdateEventFields(calendarObject, tsdavFields);
140+
} else {
141+
// Fallback to manual iCal manipulation
142+
result = manualUpdateEventFields(calendarObject, tsdavFields);
143+
}
99144

100145
// Step 4: Send the updated event back to server
101146
const updateResponse = await client.updateCalendarObject({

0 commit comments

Comments
 (0)