ti2-tourplan 1.0.141 → 1.0.142

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.
@@ -141,6 +141,7 @@ const fetchFullBookingByBookingId = async (
141
141
  hostConnectAgentID,
142
142
  itineraryBookingTypeDefs,
143
143
  itineraryBookingQuery,
144
+ rejectErrors = false,
144
145
  ) => {
145
146
  try {
146
147
  const getBookingPayload = getPayload('GetBookingRequest', {
@@ -150,12 +151,14 @@ const fetchFullBookingByBookingId = async (
150
151
  });
151
152
  const bookingReply = await callTourplan(getBookingPayload);
152
153
  const booking = R.path(['GetBookingReply'], bookingReply);
154
+ if (rejectErrors && !booking) throw new Error('GetBookingReply is missing');
153
155
  return await translateItineraryBooking({
154
156
  rootValue: booking && { ...booking, agentId: hostConnectAgentID },
155
157
  typeDefs: itineraryBookingTypeDefs,
156
158
  query: itineraryBookingQuery,
157
159
  });
158
160
  } catch (err) {
161
+ if (rejectErrors) throw err;
159
162
  const detail = err instanceof Error ? (err.stack || err.message) : String(err);
160
163
  // Log the failing identifier so the booking can be investigated without
161
164
  // crashing the whole search — the caller filters out nulls.
@@ -250,16 +253,19 @@ const searchItineraries = async ({
250
253
 
251
254
  // Step3: Build base search filters.
252
255
  if (applyBaseSearchFilters) {
256
+ baseSearchFilters = {};
253
257
  // Build base search filters.
254
258
  // If booking reference(s) or bookingid are provided these those are used.
255
259
  // But if no booking reference(s) or bookingid are provided then we use the travel
256
260
  // dates window as a base search filters. To keep the search bounded (and not crash Tourplan)
257
261
  // If purchase dates are provided then its part of base search filters.
258
- const travelDateWindow = resolveTravelDateWindow(travelDateStart, travelDateEnd);
259
- baseSearchFilters = {
260
- TravelDateFrom: travelDateWindow.from,
261
- TravelDateTo: travelDateWindow.to,
262
- };
262
+ if (!(purchaseDateStart && purchaseDateEnd) || travelDateStart || travelDateEnd) {
263
+ const travelDateWindow = resolveTravelDateWindow(travelDateStart, travelDateEnd);
264
+ baseSearchFilters = {
265
+ TravelDateFrom: travelDateWindow.from,
266
+ TravelDateTo: travelDateWindow.to,
267
+ };
268
+ }
263
269
  if (purchaseDateStart || purchaseDateEnd) {
264
270
  const purchaseDateWindow = resolvePurchaseDateWindow(purchaseDateStart, purchaseDateEnd);
265
271
  baseSearchFilters.BookingEnteredDateFrom = purchaseDateWindow.from;
@@ -268,6 +274,8 @@ const searchItineraries = async ({
268
274
  }
269
275
 
270
276
  // Step4: Fetch for bookings based on the search criterias.
277
+ const enteredDateOnly = Boolean(applyBaseSearchFilters && purchaseDateStart && purchaseDateEnd
278
+ && !travelDateStart && !travelDateEnd);
271
279
  const allSearches = searchCriteriaGroups.length
272
280
  ? searchCriteriaGroups
273
281
  : [[baseSearchFilters]];
@@ -318,7 +326,7 @@ const searchItineraries = async ({
318
326
  */
319
327
  } catch (err) {
320
328
  const errMsg = typeof err === 'string' ? err : (err && err.message) || String(err);
321
- if (hasAgentReferenceIds) {
329
+ if (hasAgentReferenceIds || enteredDateOnly) {
322
330
  throw err instanceof Error ? err : Error(errMsg);
323
331
  }
324
332
  if (errMsg.includes('Request failed with status code')) throw Error(errMsg);
@@ -407,6 +415,7 @@ const searchItineraries = async ({
407
415
  hostConnectAgentID,
408
416
  itineraryBookingTypeDefs,
409
417
  itineraryBookingQuery,
418
+ enteredDateOnly,
410
419
  ),
411
420
  { concurrency: 10 },
412
421
  );
@@ -53,6 +53,41 @@ describe('searchItineraries agentReferenceIds', () => {
53
53
  .map(([request]) => request.model.ListBookingsRequest)
54
54
  .filter(Boolean);
55
55
 
56
+ it('uses entered-date filters without silently restricting travel dates', async () => {
57
+ const callTourplan = jest.fn(async () => ({
58
+ ListBookingsReply: { BookingHeaders: { BookingHeader: [] } },
59
+ }));
60
+ await runSearch({ purchaseDateStart: '2026-02-01', purchaseDateEnd: '2026-02-02' }, callTourplan);
61
+ expect(listRequestsFrom(callTourplan)).toEqual([{
62
+ AgentID: 'agent-id', Password: 'agent-password',
63
+ BookingEnteredDateFrom: '2026-02-01', BookingEnteredDateTo: '2026-02-02',
64
+ }]);
65
+ callTourplan.mockClear();
66
+ await runSearch({ purchaseDateStart: '2026-02-01', purchaseDateEnd: '2026-02-02',
67
+ travelDateStart: '2028-01-01', travelDateEnd: '2028-01-31' }, callTourplan);
68
+ expect(listRequestsFrom(callTourplan)[0]).toMatchObject({
69
+ BookingEnteredDateFrom: '2026-02-01', BookingEnteredDateTo: '2026-02-02',
70
+ TravelDateFrom: '2028-01-01', TravelDateTo: '2028-01-31',
71
+ });
72
+ });
73
+
74
+ it('propagates entered-date retrieval timeouts instead of reporting successful empty coverage', async () => {
75
+ const timeout = Object.assign(new Error('timed out'), { code: 'ETIMEDOUT' });
76
+ const callTourplan = jest.fn().mockRejectedValue(timeout);
77
+ await expect(runSearch({ purchaseDateStart: '2026-02-01', purchaseDateEnd: '2026-02-02' }, callTourplan))
78
+ .rejects.toMatchObject({ code: 'ETIMEDOUT' });
79
+ expect(callTourplan).toHaveBeenCalledTimes(1);
80
+ });
81
+
82
+ it('fails entered-date retrieval if a booking detail cannot be fetched', async () => {
83
+ const callTourplan = jest.fn(async ({ model }) => {
84
+ if (model.ListBookingsRequest) return { ListBookingsReply: { BookingHeaders: { BookingHeader: [{ BookingId: 'A' }] } } };
85
+ throw Object.assign(new Error('detail timeout'), { code: 'ETIMEDOUT' });
86
+ });
87
+ await expect(runSearch({ purchaseDateStart: '2026-02-01', purchaseDateEnd: '2026-02-02' }, callTourplan))
88
+ .rejects.toMatchObject({ code: 'ETIMEDOUT' });
89
+ });
90
+
56
91
  it('treats a numeric agentReferenceIds value as an exact AgentRef with explicit precedence', async () => {
57
92
  const callTourplan = jest.fn(async ({ model }) => {
58
93
  if (model.ListBookingsRequest) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ti2-tourplan",
3
- "version": "1.0.141",
3
+ "version": "1.0.142",
4
4
  "description": "Tourplan's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {