ti2-bokun 1.0.8 → 1.0.14
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/index.js +94 -6
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1687,8 +1687,6 @@ class Plugin {
|
|
|
1687
1687
|
// fields → per-passenger contact info (handled separately, explained below)
|
|
1688
1688
|
const participantContactFields = participant?.fields || [];
|
|
1689
1689
|
|
|
1690
|
-
console.log('SACHIN participantCustomFieldValues: ', JSON.stringify(participantCustomFieldValues, null, 2));
|
|
1691
|
-
console.log('SACHIN participantContactFields: ', JSON.stringify(participantContactFields, null, 2));
|
|
1692
1690
|
const participantAnswers = participantCustomFieldValues
|
|
1693
1691
|
.map(entry => {
|
|
1694
1692
|
const questionId = entry?.field?.id || entry?.field?.questionId;
|
|
@@ -1701,7 +1699,6 @@ class Plugin {
|
|
|
1701
1699
|
})
|
|
1702
1700
|
.filter(Boolean);
|
|
1703
1701
|
|
|
1704
|
-
console.log('SACHIN participantAnswers: ', JSON.stringify(participantAnswers, null, 2));
|
|
1705
1702
|
const passengerDetails = participantContactFields
|
|
1706
1703
|
.map(entry => {
|
|
1707
1704
|
const questionId = entry?.field?.id || entry?.field?.questionId;
|
|
@@ -1715,7 +1712,6 @@ class Plugin {
|
|
|
1715
1712
|
})
|
|
1716
1713
|
.filter(Boolean);
|
|
1717
1714
|
|
|
1718
|
-
console.log('SACHIN passengerDetails: ', JSON.stringify(passengerDetails, null, 2));
|
|
1719
1715
|
// Indexed customFieldValues (field|N suffix) also scoped to this passenger
|
|
1720
1716
|
const indexedAnswers = (passengerAnswersByIndex[passengerIndex] || [])
|
|
1721
1717
|
.map(a => ({ ...a, passengerIndex }));
|
|
@@ -1930,12 +1926,44 @@ class Plugin {
|
|
|
1930
1926
|
token,
|
|
1931
1927
|
payload: { bookingId, reference, dateFormat: _dateFormat },
|
|
1932
1928
|
typeDefsAndQueries: { bookingTypeDefs, bookingQuery },
|
|
1929
|
+
}) {
|
|
1930
|
+
const normalizedBookingId = bookingId != null ? String(bookingId).trim() : '';
|
|
1931
|
+
const normalizedReference = reference != null ? String(reference).trim() : '';
|
|
1932
|
+
|
|
1933
|
+
if (normalizedBookingId) {
|
|
1934
|
+
return this.searchByBookingId({
|
|
1935
|
+
axios,
|
|
1936
|
+
token,
|
|
1937
|
+
bookingId: normalizedBookingId,
|
|
1938
|
+
bookingTypeDefs,
|
|
1939
|
+
bookingQuery,
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
if (!normalizedReference) {
|
|
1944
|
+
throw new Error('Either bookingId or reference is required');
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
return this.searchByBookingRef({
|
|
1948
|
+
axios,
|
|
1949
|
+
token,
|
|
1950
|
+
reference: normalizedReference,
|
|
1951
|
+
bookingTypeDefs,
|
|
1952
|
+
bookingQuery,
|
|
1953
|
+
});
|
|
1954
|
+
}
|
|
1955
|
+
|
|
1956
|
+
async searchByBookingId({
|
|
1957
|
+
axios,
|
|
1958
|
+
token,
|
|
1959
|
+
bookingId,
|
|
1960
|
+
bookingTypeDefs,
|
|
1961
|
+
bookingQuery,
|
|
1933
1962
|
}) {
|
|
1934
1963
|
const { endpoint, testMode } = token || {};
|
|
1935
1964
|
const { accessKey, secretKey } = this.getCredentials(token);
|
|
1936
1965
|
const baseUrl = testMode ? 'https://api.bokuntest.com' : (endpoint || this.endpoint || 'https://api.bokun.io');
|
|
1937
|
-
const
|
|
1938
|
-
const path = `/booking.json/booking/${searchParam}`;
|
|
1966
|
+
const path = `/booking.json/booking/${bookingId}`;
|
|
1939
1967
|
const { url, pathForSigning } = buildRequestUrlAndPath(baseUrl, path);
|
|
1940
1968
|
const headers = getHeaders({
|
|
1941
1969
|
accessKey,
|
|
@@ -1971,6 +1999,66 @@ class Plugin {
|
|
|
1971
1999
|
throw err;
|
|
1972
2000
|
}
|
|
1973
2001
|
}
|
|
2002
|
+
|
|
2003
|
+
async searchByBookingRef({
|
|
2004
|
+
axios,
|
|
2005
|
+
token,
|
|
2006
|
+
reference,
|
|
2007
|
+
bookingTypeDefs,
|
|
2008
|
+
bookingQuery,
|
|
2009
|
+
}) {
|
|
2010
|
+
const { endpoint, testMode } = token || {};
|
|
2011
|
+
const { accessKey, secretKey } = this.getCredentials(token);
|
|
2012
|
+
const baseUrl = testMode ? 'https://api.bokuntest.com' : (endpoint || this.endpoint || 'https://api.bokun.io');
|
|
2013
|
+
const path = '/booking.json/booking-search';
|
|
2014
|
+
const { url, pathForSigning } = buildRequestUrlAndPath(baseUrl, path);
|
|
2015
|
+
const headers = getHeaders({
|
|
2016
|
+
accessKey,
|
|
2017
|
+
secretKey,
|
|
2018
|
+
method: 'POST',
|
|
2019
|
+
path: pathForSigning,
|
|
2020
|
+
});
|
|
2021
|
+
|
|
2022
|
+
try {
|
|
2023
|
+
const response = await axios({
|
|
2024
|
+
method: 'post',
|
|
2025
|
+
url,
|
|
2026
|
+
headers,
|
|
2027
|
+
data: {
|
|
2028
|
+
externalBookingReference: reference,
|
|
2029
|
+
},
|
|
2030
|
+
});
|
|
2031
|
+
|
|
2032
|
+
const items = R.path(['data', 'items'], response);
|
|
2033
|
+
const bookingIds = Array.isArray(items)
|
|
2034
|
+
? R.uniq(
|
|
2035
|
+
items
|
|
2036
|
+
.filter(item => item && item.externalBookingReference === reference)
|
|
2037
|
+
.map(item => item.id)
|
|
2038
|
+
.filter(Boolean),
|
|
2039
|
+
)
|
|
2040
|
+
: [];
|
|
2041
|
+
|
|
2042
|
+
if (bookingIds.length === 0) {
|
|
2043
|
+
return ({ bookings: [] });
|
|
2044
|
+
}
|
|
2045
|
+
|
|
2046
|
+
const bookingResults = await Promise.map(bookingIds, bookingIdResult => this.searchByBookingId({
|
|
2047
|
+
axios,
|
|
2048
|
+
token,
|
|
2049
|
+
bookingId: bookingIdResult,
|
|
2050
|
+
bookingTypeDefs,
|
|
2051
|
+
bookingQuery,
|
|
2052
|
+
}), { concurrency: CONCURRENCY });
|
|
2053
|
+
|
|
2054
|
+
return ({
|
|
2055
|
+
bookings: bookingResults.flatMap(result => result?.bookings || []),
|
|
2056
|
+
});
|
|
2057
|
+
} catch (err) {
|
|
2058
|
+
console.error('Error searching booking by external reference:', err.response?.data || err.message);
|
|
2059
|
+
throw err;
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
1974
2062
|
}
|
|
1975
2063
|
|
|
1976
2064
|
module.exports = Plugin;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ti2-bokun",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
4
4
|
"description": "Bokun's TI2 Plugin",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"jest-diff": "^27.4.2",
|
|
54
54
|
"jest-environment-node": "27.4",
|
|
55
55
|
"jest-util": "27.4",
|
|
56
|
-
"ti2": "
|
|
56
|
+
"ti2": "file:../ti2"
|
|
57
57
|
}
|
|
58
58
|
}
|