@siftd/connect-agent 0.2.43 → 0.2.44
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/tools/calendar.js +21 -14
- package/package.json +1 -1
package/dist/tools/calendar.js
CHANGED
|
@@ -188,32 +188,39 @@ export class CalendarTools {
|
|
|
188
188
|
}
|
|
189
189
|
normalizeTodoItems(inputItems, existingItems) {
|
|
190
190
|
const existingById = new Map(existingItems.map((item) => [item.id, item]));
|
|
191
|
-
const
|
|
191
|
+
const titleToId = new Map(existingItems.map((item) => [item.title.trim().toLowerCase(), item.id]));
|
|
192
192
|
for (const rawItem of inputItems) {
|
|
193
193
|
if (!rawItem || typeof rawItem.title !== 'string' || !rawItem.title.trim())
|
|
194
194
|
continue;
|
|
195
195
|
const title = rawItem.title.trim();
|
|
196
|
-
const
|
|
196
|
+
const titleKey = title.toLowerCase();
|
|
197
|
+
const existingId = titleToId.get(titleKey);
|
|
198
|
+
const requestedId = typeof rawItem.id === 'string' && rawItem.id.trim()
|
|
197
199
|
? rawItem.id.trim()
|
|
198
|
-
:
|
|
199
|
-
const
|
|
200
|
-
const
|
|
201
|
-
const
|
|
200
|
+
: undefined;
|
|
201
|
+
const fallbackId = stableId('todo', [title, rawItem.due]);
|
|
202
|
+
const id = requestedId || existingId || fallbackId;
|
|
203
|
+
const previous = existingById.get(id) || (existingId ? existingById.get(existingId) : undefined);
|
|
204
|
+
const resolvedId = previous?.id || id;
|
|
205
|
+
const priority = rawItem.priority === 'low' || rawItem.priority === 'high'
|
|
206
|
+
? rawItem.priority
|
|
207
|
+
: previous?.priority || 'medium';
|
|
208
|
+
const due = typeof rawItem.due === 'string' && rawItem.due.trim() ? rawItem.due.trim() : previous?.due;
|
|
209
|
+
const notes = typeof rawItem.notes === 'string' && rawItem.notes.trim() ? rawItem.notes.trim() : previous?.notes;
|
|
202
210
|
const incomingSubtasks = Array.isArray(rawItem.subtasks)
|
|
203
211
|
? rawItem.subtasks
|
|
204
212
|
.filter((subtask) => subtask && typeof subtask.title === 'string' && subtask.title.trim())
|
|
205
213
|
.map((subtask, index) => ({
|
|
206
214
|
id: typeof subtask.id === 'string' && subtask.id.trim()
|
|
207
215
|
? subtask.id.trim()
|
|
208
|
-
: stableId('subtask', [
|
|
216
|
+
: stableId('subtask', [resolvedId, subtask.title.trim(), String(index)]),
|
|
209
217
|
title: subtask.title.trim(),
|
|
210
218
|
done: Boolean(subtask.done),
|
|
211
219
|
notes: typeof subtask.notes === 'string' && subtask.notes.trim() ? subtask.notes.trim() : undefined,
|
|
212
220
|
}))
|
|
213
221
|
: undefined;
|
|
214
|
-
const previous = existingById.get(id);
|
|
215
222
|
const subtasks = incomingSubtasks || previous?.subtasks;
|
|
216
|
-
let done =
|
|
223
|
+
let done = typeof rawItem.done === 'boolean' ? rawItem.done : (previous?.done ?? false);
|
|
217
224
|
if (incomingSubtasks && incomingSubtasks.length > 0) {
|
|
218
225
|
done = incomingSubtasks.every((subtask) => subtask.done);
|
|
219
226
|
}
|
|
@@ -222,11 +229,11 @@ export class CalendarTools {
|
|
|
222
229
|
for (const subtask of previous.subtasks)
|
|
223
230
|
subtask.done = true;
|
|
224
231
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
232
|
+
if (previous && previous.id !== resolvedId) {
|
|
233
|
+
existingById.delete(previous.id);
|
|
234
|
+
}
|
|
235
|
+
existingById.set(resolvedId, { id: resolvedId, title, done, due, priority, notes, subtasks });
|
|
236
|
+
titleToId.set(titleKey, resolvedId);
|
|
230
237
|
}
|
|
231
238
|
return Array.from(existingById.values());
|
|
232
239
|
}
|