ti2-tourplan 1.0.141 → 1.0.143

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.
@@ -0,0 +1,10 @@
1
+ {
2
+ "permissions": {
3
+ "allow": [
4
+ "Bash(gh pr diff:*)",
5
+ "Bash(gh pr view:*)"
6
+ ],
7
+ "deny": [],
8
+ "ask": []
9
+ }
10
+ }
package/index.js CHANGED
@@ -28,10 +28,12 @@ const defaultXmlOptions = {
28
28
  },
29
29
  };
30
30
  const urlRegExp = /^(?!mailto:)(?:(?:http|https|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?:(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[0-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))|localhost)(?::\d{2,5})?(?:(\/|\?|#)[^\s]*)?$/i;
31
- const getHeaders = ({ length }) => ({
31
+ // Content-Length counts bytes. String length undercounts multibyte UTF-8
32
+ // characters, and Tourplan then parses a truncated document (TC-2059).
33
+ const getHeaders = xmlPayload => ({
32
34
  Accept: 'application/xml',
33
35
  'Content-Type': 'application/xml; charset=utf-8',
34
- 'Content-Length': length,
36
+ 'Content-Length': Buffer.byteLength(xmlPayload, 'utf8'),
35
37
  });
36
38
 
37
39
  /**
@@ -250,7 +252,7 @@ class BuyerPlugin {
250
252
  method: 'post',
251
253
  url: endpoint,
252
254
  data: testData,
253
- headers: getHeaders({ length: testData.length }),
255
+ headers: getHeaders(testData),
254
256
  });
255
257
 
256
258
  // The API returns 200 even for DTD errors, so check the response content
@@ -350,7 +352,7 @@ class BuyerPlugin {
350
352
  // data: {
351
353
  // url: endpoint,
352
354
  // data,
353
- // headers: getHeaders({ length: `${data.length}` }),
355
+ // headers: getHeaders(data),
354
356
  // },
355
357
  // }));
356
358
  // } catch (err) {
@@ -365,7 +367,7 @@ class BuyerPlugin {
365
367
  method: 'post',
366
368
  url: endpoint,
367
369
  data,
368
- headers: getHeaders({ length: data.length }),
370
+ headers: getHeaders(data),
369
371
  };
370
372
  const reply = R.path(['data'], await axios(axiospayload));
371
373
  if (this.xmlProxyUrl) {
@@ -538,7 +540,7 @@ class BuyerPlugin {
538
540
  method: 'post',
539
541
  url: endpoint,
540
542
  data: requestData,
541
- headers: getHeaders({ length: requestData.length }),
543
+ headers: getHeaders(requestData),
542
544
  }));
543
545
  if (verbose) console.log('reply', cleanLog(reply));
544
546
  const returnObj = await xmlParser.parseStringPromise(reply);
@@ -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.143",
4
4
  "description": "Tourplan's TI2 Plugin",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -0,0 +1,91 @@
1
+ /* globals describe, it, expect, jest */
2
+
3
+ const http = require('http');
4
+ const realAxios = require('axios');
5
+ const { XMLValidator } = require('fast-xml-parser');
6
+ const Plugin = require('./index');
7
+ const { escapeInvalidXmlChars, hostConnectXmlOptions } = require('./utils');
8
+
9
+ const okReply = '<?xml version="1.0"?><Reply><AddServiceReply><BookingId>1</BookingId></AddServiceReply></Reply>';
10
+
11
+ const makeAxios = (reply = okReply) => {
12
+ const calls = [];
13
+ const axios = jest.fn(async config => {
14
+ calls.push(config);
15
+ return { data: reply };
16
+ });
17
+ return { axios, calls };
18
+ };
19
+
20
+ const expectUtf8ContentLength = config => {
21
+ expect(config.headers['Content-Length']).toBe(Buffer.byteLength(config.data, 'utf8'));
22
+ };
23
+
24
+ describe('Tourplan request Content-Length', () => {
25
+ const endpoint = 'https://test.example.com';
26
+ const xmlOptions = { prettyPrinting: { enabled: false }, dtd: { include: true, name: 'tourConnect_4_00_000.dtd' } };
27
+
28
+ it.each([
29
+ ['ASCII', 'Pickup 07:30 - meet driver in the lobby'],
30
+ ['em dash', 'Pickup 07:30 — meet driver in the lobby'],
31
+ ['accented letters', 'Café Zürich, señor'],
32
+ ['euro sign', 'Deposit €50 paid'],
33
+ ['arrow', 'Sydney → Cairns'],
34
+ ['CJK', '日本のお客様'],
35
+ ])('callTourplan declares the UTF-8 byte length for %s remarks', async (_label, notes) => {
36
+ const app = new Plugin();
37
+ const { axios, calls } = makeAxios();
38
+ await app.callTourplan({
39
+ endpoint,
40
+ axios,
41
+ xmlOptions,
42
+ model: { AddServiceRequest: { Opt: 'SYDACSYDHOTSTD', Remarks: notes } },
43
+ });
44
+ const addService = calls.find(c => c.data.includes('AddServiceRequest'));
45
+ const dtdDetection = calls.find(c => c.data.includes('AuthenticationRequest'));
46
+ expectUtf8ContentLength(addService);
47
+ // The DTD probe body is ASCII; this only checks it uses the same header helper.
48
+ expectUtf8ContentLength(dtdDetection);
49
+ });
50
+
51
+ it('queryAllotment declares the UTF-8 byte length', async () => {
52
+ const app = new Plugin();
53
+ const { axios, calls } = makeAxios('<Reply><GetInventoryReply></GetInventoryReply></Reply>');
54
+ await app.queryAllotment({
55
+ axios,
56
+ token: { endpoint, username: 'agent—ops', password: 'pw' },
57
+ payload: { startDate: '01/08/2022', endDate: '15/08/2022', keyPath: 'MAGLUX|SYDACMAGLUXDELXRO' },
58
+ });
59
+ const inventory = calls.find(c => c.data.includes('GetInventoryRequest'));
60
+ expect(Buffer.byteLength(inventory.data, 'utf8')).toBeGreaterThan(inventory.data.length);
61
+ expectUtf8ContentLength(inventory);
62
+ });
63
+
64
+ // Node's HTTP parser, like Tourplan, reads exactly Content-Length bytes of the body.
65
+ it('sends a complete HostConnect AddServiceRequest with an em dash over HTTP', async () => {
66
+ const received = [];
67
+ const server = http.createServer((req, res) => {
68
+ const chunks = [];
69
+ req.on('data', chunk => chunks.push(chunk));
70
+ req.on('end', () => {
71
+ received.push(Buffer.concat(chunks).toString('utf8'));
72
+ res.setHeader('Content-Type', 'application/xml');
73
+ res.end(okReply);
74
+ });
75
+ });
76
+ await new Promise(resolve => { server.listen(0, '127.0.0.1', resolve); });
77
+ try {
78
+ await new Plugin().callTourplan({
79
+ endpoint: `http://127.0.0.1:${server.address().port}/`,
80
+ axios: realAxios,
81
+ xmlOptions: hostConnectXmlOptions,
82
+ model: { AddServiceRequest: { Opt: 'SYDACSYDHOTSTD', Remarks: escapeInvalidXmlChars('Pickup 07:30 \u2014 meet driver') } },
83
+ });
84
+ } finally {
85
+ server.close();
86
+ }
87
+ expect(received).toHaveLength(1);
88
+ expect(received[0].endsWith('</Request>')).toBe(true);
89
+ expect(XMLValidator.validate(received[0])).toBe(true);
90
+ });
91
+ });