@remit/mailbox-service 0.0.107 → 0.0.109
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/package.json
CHANGED
|
@@ -7,20 +7,17 @@
|
|
|
7
7
|
|
|
8
8
|
import assert from "node:assert/strict";
|
|
9
9
|
import { describe, it } from "node:test";
|
|
10
|
+
import { MemoryCalendarStore } from "@remit/calendar-service/memory-store";
|
|
10
11
|
import type {
|
|
11
12
|
CalendarSuggestionItem,
|
|
12
13
|
FilterItem,
|
|
13
14
|
IAddressRepository,
|
|
14
|
-
ICalendarSuggestionRepository,
|
|
15
15
|
ICalendarUnitOfWork,
|
|
16
16
|
IEnvelopeRepository,
|
|
17
17
|
IFilterRepository,
|
|
18
18
|
IMessageRepository,
|
|
19
19
|
IThreadMessageRepository,
|
|
20
|
-
PutCalendarSuggestionInput,
|
|
21
|
-
ResultList,
|
|
22
20
|
} from "@remit/data-ports";
|
|
23
|
-
import { deriveCalendarSuggestionId } from "@remit/data-ports/id";
|
|
24
21
|
import {
|
|
25
22
|
CalendarInviteMethod,
|
|
26
23
|
CalendarSuggestionSource,
|
|
@@ -133,90 +130,9 @@ const PLAIN_EML = Buffer.from(
|
|
|
133
130
|
].join("\r\n"),
|
|
134
131
|
);
|
|
135
132
|
|
|
136
|
-
class MemorySuggestions implements ICalendarSuggestionRepository {
|
|
137
|
-
readonly rows = new Map<string, CalendarSuggestionItem>();
|
|
138
|
-
|
|
139
|
-
async put(
|
|
140
|
-
input: PutCalendarSuggestionInput,
|
|
141
|
-
): Promise<CalendarSuggestionItem> {
|
|
142
|
-
const suggestionId = deriveCalendarSuggestionId(
|
|
143
|
-
input.messageId,
|
|
144
|
-
input.bodyPartId,
|
|
145
|
-
input.icalUid,
|
|
146
|
-
);
|
|
147
|
-
const existing = this.rows.get(suggestionId);
|
|
148
|
-
const row: CalendarSuggestionItem = {
|
|
149
|
-
...input,
|
|
150
|
-
suggestionId,
|
|
151
|
-
state: existing?.state ?? CalendarSuggestionState.Pending,
|
|
152
|
-
acceptedCalendarObjectId: existing?.acceptedCalendarObjectId ?? "",
|
|
153
|
-
createdAt: existing?.createdAt ?? 1,
|
|
154
|
-
updatedAt: 1,
|
|
155
|
-
};
|
|
156
|
-
this.rows.set(suggestionId, row);
|
|
157
|
-
return row;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
async get(
|
|
161
|
-
_accountConfigId: string,
|
|
162
|
-
suggestionId: string,
|
|
163
|
-
): Promise<CalendarSuggestionItem> {
|
|
164
|
-
const row = this.rows.get(suggestionId);
|
|
165
|
-
if (!row) throw new Error(`missing ${suggestionId}`);
|
|
166
|
-
return row;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
async listByMessage(
|
|
170
|
-
_accountConfigId: string,
|
|
171
|
-
messageId: string,
|
|
172
|
-
): Promise<CalendarSuggestionItem[]> {
|
|
173
|
-
return [...this.rows.values()].filter((row) => row.messageId === messageId);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
async listByState(
|
|
177
|
-
_accountConfigId: string,
|
|
178
|
-
state: CalendarSuggestionItem["state"],
|
|
179
|
-
): Promise<ResultList<CalendarSuggestionItem>> {
|
|
180
|
-
return {
|
|
181
|
-
items: [...this.rows.values()].filter((row) => row.state === state),
|
|
182
|
-
continuationToken: undefined,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
async settle(
|
|
187
|
-
_accountConfigId: string,
|
|
188
|
-
suggestionId: string,
|
|
189
|
-
input: {
|
|
190
|
-
state: CalendarSuggestionItem["state"];
|
|
191
|
-
acceptedCalendarObjectId: string;
|
|
192
|
-
},
|
|
193
|
-
): Promise<CalendarSuggestionItem> {
|
|
194
|
-
const row = this.rows.get(suggestionId);
|
|
195
|
-
if (!row) throw new Error(`missing ${suggestionId}`);
|
|
196
|
-
const settled = { ...row, ...input };
|
|
197
|
-
this.rows.set(suggestionId, settled);
|
|
198
|
-
return settled;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
async supersedeIfPending(
|
|
202
|
-
_accountConfigId: string,
|
|
203
|
-
suggestionId: string,
|
|
204
|
-
): Promise<CalendarSuggestionItem | null> {
|
|
205
|
-
const row = this.rows.get(suggestionId);
|
|
206
|
-
if (!row || row.state !== CalendarSuggestionState.Pending) return null;
|
|
207
|
-
const retired = {
|
|
208
|
-
...row,
|
|
209
|
-
state: CalendarSuggestionState.Superseded,
|
|
210
|
-
acceptedCalendarObjectId: "",
|
|
211
|
-
};
|
|
212
|
-
this.rows.set(suggestionId, retired);
|
|
213
|
-
return retired;
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
133
|
interface Harness {
|
|
218
134
|
service: BodySyncService;
|
|
219
|
-
suggestions:
|
|
135
|
+
suggestions: Map<string, CalendarSuggestionItem>;
|
|
220
136
|
}
|
|
221
137
|
|
|
222
138
|
const buildHarness = ({
|
|
@@ -230,7 +146,8 @@ const buildHarness = ({
|
|
|
230
146
|
withCalendarConfig?: boolean;
|
|
231
147
|
mutedSenderFilters?: FilterItem[];
|
|
232
148
|
} = {}): Harness => {
|
|
233
|
-
const
|
|
149
|
+
const store = new MemoryCalendarStore();
|
|
150
|
+
const suggestions = store.calendarSuggestion;
|
|
234
151
|
|
|
235
152
|
const messageService = {
|
|
236
153
|
get: async (messageId: string) => ({
|
|
@@ -330,7 +247,7 @@ const buildHarness = ({
|
|
|
330
247
|
: undefined,
|
|
331
248
|
);
|
|
332
249
|
|
|
333
|
-
return { service, suggestions };
|
|
250
|
+
return { service, suggestions: store.suggestions };
|
|
334
251
|
};
|
|
335
252
|
|
|
336
253
|
const readBody = async (
|
|
@@ -357,7 +274,7 @@ describe("mail-derived calendar suggestions (issue #1033)", () => {
|
|
|
357
274
|
|
|
358
275
|
await readBody(harness.service, INVITATION_EML());
|
|
359
276
|
|
|
360
|
-
const rows = [...harness.suggestions.
|
|
277
|
+
const rows = [...harness.suggestions.values()];
|
|
361
278
|
assert.equal(rows.length, 1);
|
|
362
279
|
assert.equal(rows[0]?.state, CalendarSuggestionState.Pending);
|
|
363
280
|
assert.equal(rows[0]?.icalUid, UID);
|
|
@@ -372,7 +289,7 @@ describe("mail-derived calendar suggestions (issue #1033)", () => {
|
|
|
372
289
|
|
|
373
290
|
await readBody(harness.service, INVITATION_EML());
|
|
374
291
|
|
|
375
|
-
const row = [...harness.suggestions.
|
|
292
|
+
const row = [...harness.suggestions.values()][0];
|
|
376
293
|
assert.match(row?.icalData ?? "", /BEGIN:VCALENDAR/);
|
|
377
294
|
assert.match(row?.icalData ?? "", /UID:invite-4711@example\.test/);
|
|
378
295
|
});
|
|
@@ -385,7 +302,7 @@ describe("mail-derived calendar suggestions (issue #1033)", () => {
|
|
|
385
302
|
|
|
386
303
|
await readBody(harness.service, FLOATING_INVITATION_EML);
|
|
387
304
|
|
|
388
|
-
const row = [...harness.suggestions.
|
|
305
|
+
const row = [...harness.suggestions.values()][0];
|
|
389
306
|
assert.equal(row?.dtStart, "2026-09-01T10:00:00+02:00");
|
|
390
307
|
assert.equal(row?.zoneCertainty, "Local");
|
|
391
308
|
});
|
|
@@ -400,7 +317,7 @@ describe("mail-derived calendar suggestions (issue #1033)", () => {
|
|
|
400
317
|
|
|
401
318
|
await readBody(harness.service, INVITATION_EML());
|
|
402
319
|
|
|
403
|
-
assert.equal(harness.suggestions.
|
|
320
|
+
assert.equal(harness.suggestions.size, 0);
|
|
404
321
|
});
|
|
405
322
|
|
|
406
323
|
it("still offers a card when the rule names a different sender", async () => {
|
|
@@ -410,7 +327,7 @@ describe("mail-derived calendar suggestions (issue #1033)", () => {
|
|
|
410
327
|
|
|
411
328
|
await readBody(harness.service, INVITATION_EML());
|
|
412
329
|
|
|
413
|
-
assert.equal(harness.suggestions.
|
|
330
|
+
assert.equal(harness.suggestions.size, 1);
|
|
414
331
|
});
|
|
415
332
|
|
|
416
333
|
it("still offers a card when the rule about this sender does something", async () => {
|
|
@@ -427,7 +344,7 @@ describe("mail-derived calendar suggestions (issue #1033)", () => {
|
|
|
427
344
|
|
|
428
345
|
await readBody(harness.service, INVITATION_EML());
|
|
429
346
|
|
|
430
|
-
assert.equal(harness.suggestions.
|
|
347
|
+
assert.equal(harness.suggestions.size, 1);
|
|
431
348
|
});
|
|
432
349
|
|
|
433
350
|
it("offers nothing for a message carrying no calendar part", async () => {
|
|
@@ -435,7 +352,7 @@ describe("mail-derived calendar suggestions (issue #1033)", () => {
|
|
|
435
352
|
|
|
436
353
|
await readBody(harness.service, PLAIN_EML);
|
|
437
354
|
|
|
438
|
-
assert.equal(harness.suggestions.
|
|
355
|
+
assert.equal(harness.suggestions.size, 0);
|
|
439
356
|
});
|
|
440
357
|
|
|
441
358
|
it("offers nothing on a forced body re-sync", async () => {
|
|
@@ -450,7 +367,7 @@ describe("mail-derived calendar suggestions (issue #1033)", () => {
|
|
|
450
367
|
// The pass genuinely ran — the body was re-fetched and re-stored — and
|
|
451
368
|
// still offered nothing.
|
|
452
369
|
assert.equal(result.storedAt, "s3://bodies/m-1");
|
|
453
|
-
assert.equal(harness.suggestions.
|
|
370
|
+
assert.equal(harness.suggestions.size, 0);
|
|
454
371
|
});
|
|
455
372
|
|
|
456
373
|
it("supersedes the earlier revision when a higher SEQUENCE arrives", async () => {
|
|
@@ -459,7 +376,7 @@ describe("mail-derived calendar suggestions (issue #1033)", () => {
|
|
|
459
376
|
await readBody(harness.service, INVITATION_EML(0), "m-1");
|
|
460
377
|
await readBody(harness.service, INVITATION_EML(1), "m-2");
|
|
461
378
|
|
|
462
|
-
const rows = [...harness.suggestions.
|
|
379
|
+
const rows = [...harness.suggestions.values()];
|
|
463
380
|
assert.equal(rows.length, 2);
|
|
464
381
|
assert.deepEqual(
|
|
465
382
|
rows.map((row) => `${row.messageId}:${row.state}`).sort(),
|
|
@@ -472,7 +389,7 @@ describe("mail-derived calendar suggestions (issue #1033)", () => {
|
|
|
472
389
|
|
|
473
390
|
await readBody(harness.service, INVITATION_EML(1, "CANCEL"));
|
|
474
391
|
|
|
475
|
-
const row = [...harness.suggestions.
|
|
392
|
+
const row = [...harness.suggestions.values()][0];
|
|
476
393
|
assert.equal(row?.method, CalendarInviteMethod.Cancel);
|
|
477
394
|
assert.equal(row?.state, CalendarSuggestionState.Pending);
|
|
478
395
|
assert.equal(row?.acceptedCalendarObjectId, "");
|
|
@@ -503,7 +420,7 @@ describe("mail-derived calendar suggestions (issue #1033)", () => {
|
|
|
503
420
|
const result = await readBody(harness.service, broken);
|
|
504
421
|
|
|
505
422
|
assert.equal(result.storedAt, "newly-stored");
|
|
506
|
-
assert.equal(harness.suggestions.
|
|
423
|
+
assert.equal(harness.suggestions.size, 0);
|
|
507
424
|
});
|
|
508
425
|
|
|
509
426
|
it("is a no-op when body sync was built without a CalendarSuggestionConfig", async () => {
|
|
@@ -511,6 +428,6 @@ describe("mail-derived calendar suggestions (issue #1033)", () => {
|
|
|
511
428
|
|
|
512
429
|
await readBody(harness.service, INVITATION_EML());
|
|
513
430
|
|
|
514
|
-
assert.equal(harness.suggestions.
|
|
431
|
+
assert.equal(harness.suggestions.size, 0);
|
|
515
432
|
});
|
|
516
433
|
});
|