The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
fix(mail-ingest): keep a booking that fails the item shape in the inbox
Maurice303d161ecf3b
diff --git a/server/src/nest/mail-ingest/mail-ingest-process.service.ts b/server/src/nest/mail-ingest/mail-ingest-process.service.tsindex adfe5586e..54dafd1fe 100644--- a/server/src/nest/mail-ingest/mail-ingest-process.service.ts+++ b/server/src/nest/mail-ingest/mail-ingest-process.service.ts@@ -295,7 +295,8 @@ export class MailIngestProcessService {messageId: message.id,userId: message.user_id,position: booking.position,- itemJson: encodeJson(MAIL_INGEST_ITEM, booking.draft.item),+ // A booking that fails the shape waits as the mail alone, to be filled in by hand.+ itemJson: booking.verdict.checks.schema === 'fail' ? null : encodeJson(MAIL_INGEST_ITEM, booking.draft.item),source: booking.draft.source,checksJson: encodeJson(MAIL_INGEST_CHECKS, booking.verdict.checks),uncertainFields: encodeJson(diff --git a/server/src/nest/mail-ingest/mail-ingest-reading.service.ts b/server/src/nest/mail-ingest/mail-ingest-reading.service.tsindex 1e9f555ac..b423b8369 100644--- a/server/src/nest/mail-ingest/mail-ingest-reading.service.ts+++ b/server/src/nest/mail-ingest/mail-ingest-reading.service.ts@@ -74,7 +74,8 @@ export class MailIngestReadingService {trips: readonly TripOption[];now: Date;}): Promise<MailReading> {- const { mail, machine, person, prefs, trips, now } = args;+ const { mail, person, prefs, trips, now } = args;+ const machine = args.machine.map(withTextReference);const skipped = await this.aiSkipped(person.id, prefs, now);const refs = trips.map((trip, i) => ({ trip, ref: `t${i + 1}` }));const reading = skipped@@ -134,7 +135,7 @@ export class MailIngestReadingService {bookings.map((booking) => this.bookingImport.mapAiReservations(booking.reservations, 'mail')),);return bookings- .flatMap((booking, i) => mapped[i].map((item) => ({ booking, item })))+ .flatMap((booking, i) => mapped[i].map((item) => ({ booking, item: withTextReference(item) }))).slice(0, MAIL_INGEST_LIMITS.storedBookings).map(({ booking, item }) => {const match = machine.find((candidate) => sameBooking(candidate, item));@@ -166,6 +167,12 @@ function fromMachine(item: BookingImportPreviewItem): MailDraft {};}+/** A reference a reader gave as a number, as the text it is. */+function withTextReference(item: BookingImportPreviewItem): BookingImportPreviewItem {+ const reference: unknown = item.confirmation_number;+ return typeof reference === 'number' ? { ...item, confirmation_number: String(reference) } : item;+}+/** A booking as a hint for the AI: what it is, when, its reference and route, no more. */function hintOf(item: BookingImportPreviewItem): Record<string, unknown> {return {diff --git a/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts b/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.tsindex a5671cb26..98f0dd08e 100644--- a/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts+++ b/server/tests/unit/nest/mail-ingest/mail-ingest.pipeline.test.ts@@ -575,6 +575,30 @@ describe('what a mail names', () => {}});+ it('keeps a booking that fails the shape in the inbox, and adds the others of the mail', async () => {+ const user = await person();+ const trip = await makeTrip(orm(), user.id, { start_date: '2030-03-01', end_date: '2030-03-10' });+ machine.mockResolvedValue([FLIGHT, { ...RETURN, title: '' }]);++ const messageId = await forward(user.id, eml('half-read', 'Fwd: Your flights', BOTH));+ expect(await findRow(orm(), MailIngestMessages, { id: messageId })).toMatchObject({ status: 'processed' });+ const entries = await entriesOf(messageId);+ expect(entries.map((entry) => [entry.resolution, entry.reason, entry.item_json === null])).toEqual([+ ['auto_applied', null, false],+ ['pending', 'missing_critical_field', true],+ ]);+ expect(await countRows(orm(), Reservations, { trip: trip.id })).toBe(1);+ });++ it('reads a reference given as a number as its text', async () => {+ const user = await person();+ const trip = await makeTrip(orm(), user.id, { start_date: '2030-03-01', end_date: '2030-03-10' });+ machine.mockResolvedValue([{ ...FLIGHT, confirmation_number: 482913 as unknown as string }]);++ const [entry] = await entriesOf(await forward(user.id, eml('numbered', 'Fwd: Booking 482913', BOTH)));+ expect(entry).toMatchObject({ resolution: 'auto_applied' });+ expect(await findRow(orm(), Reservations, { trip: trip.id })).toMatchObject({ confirmation_number: '482913' });+ });});describe('a mail that keeps failing', () => {