feat: Apple Wallet passes for bookings

"Add to Apple Wallet" on a booking in the iOS app turns it into a TREK pass:
a boarding pass from and to for flights, trains, buses and boats, check-in and
check-out for a stay, pickup and drop-off for a car, the time for anything
else, with the confirmation code as a QR code. Wallet brings it up on the lock
screen around its time and place: times carry the offset of the endpoint's zone
(looked up from the coordinates where the endpoint has none), stays and
restaurants their place's coordinates. The labels come from the booking forms'
own strings, so nothing new to translate on the pass.

Only liketrek holds the Pass Type ID certificate, so the server sends the pass's
texts to the TREK services' signer (TREK_WALLET_PASS_URL, push.liketrek.com)
once per tap; it stores nothing, and TREK_SERVICES=off turns it off with the
other services. Texts are cleaned of links and shortened here, the answer must
be a .pkpass within 512 KB, and a user gets 20 passes a minute.

- New wallet-pass domain: GET /api/trips/:tripId/reservations/:id/wallet-pass
  behind the trip guard, the booking checked to belong to the trip; trip title
  and place come from the reservations domain (findPassContext)
- MWalletButton in the transport and booking sheets, only where the app binary
  has the wallet feature; undated bookings and failures are told apart
- TREK_WALLET_PASS_URL in .env.example, compose, Helm and the wiki
This commit is contained in:
Maurice
2026-11-07 10:40:41 +01:00
parent 794da3be72
commit 37a4e84360
56 changed files with 1873 additions and 113 deletions
@@ -1032,3 +1032,40 @@ describe('ReservationsRepository — confirmIfPending', () => {
expect((await findRow(await orm(), Reservations, { id: cancelled.id }))?.status).toBe('cancelled');
});
});
describe('ReservationsRepository — findPassContext', () => {
it('RES-PASS-001: reads the trip title and the place of the booking, else of its stay, within the trip only', async () => {
const { user } = createUser(testDb);
const trip = createTrip(testDb, user.id, { title: 'Japan 2027', start_date: '2027-04-01', end_date: '2027-04-06' });
const day1 = createDay(testDb, trip.id, { date: '2027-04-01' });
const day2 = createDay(testDb, trip.id, { date: '2027-04-02' });
const restaurant = createPlace(testDb, trip.id, { name: 'Gion Karyo', lat: 35.0, lng: 135.77 });
const hotel = createPlace(testDb, trip.id, { name: 'Hotel Granvia Kyoto', lat: 34.985, lng: 135.758 });
const stay = createDayAccommodation(testDb, trip.id, hotel.id, day1.id, day2.id);
const dinner = createReservation(testDb, trip.id, { title: 'Dinner', type: 'restaurant' });
await setReservation(dinner.id, { place: restaurant.id });
const room = createReservation(testDb, trip.id, { title: 'Room', type: 'hotel' });
await setReservation(room.id, { accommodation_id: String(stay.id) });
const bare = createReservation(testDb, trip.id, { title: 'Museum', type: 'event' });
expect(await reservationsRepo.findPassContext(dinner.id, trip.id)).toEqual({
trip_title: 'Japan 2027',
place_lat: 35.0,
place_lng: 135.77,
place_name: 'Gion Karyo',
});
expect(await reservationsRepo.findPassContext(room.id, trip.id)).toMatchObject({
place_lat: 34.985,
place_name: 'Hotel Granvia Kyoto',
});
expect(await reservationsRepo.findPassContext(bare.id, trip.id)).toEqual({
trip_title: 'Japan 2027',
place_lat: null,
place_lng: null,
place_name: null,
});
const other = createTrip(testDb, user.id, { title: 'Elsewhere' });
expect(await reservationsRepo.findPassContext(dinner.id, other.id)).toBeUndefined();
});
});