@travelswitchhq/flight-search-react 1.2.3 → 1.2.4

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/dist/index.cjs CHANGED
@@ -64,6 +64,41 @@ var buildEncryptedToken = (domainName) => {
64
64
  const encrypted = encryptor.encrypt(payload);
65
65
  return typeof encrypted === "string" ? encrypted : null;
66
66
  };
67
+ var MACHINE_ID_STORAGE_KEY = "MacId";
68
+ var generateUuid = () => {
69
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
70
+ return crypto.randomUUID();
71
+ }
72
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
73
+ const r = Math.random() * 16 | 0;
74
+ return (c === "x" ? r : r & 3 | 8).toString(16);
75
+ });
76
+ };
77
+ var getMachineId = () => {
78
+ try {
79
+ let machineId = localStorage.getItem(MACHINE_ID_STORAGE_KEY);
80
+ if (!machineId) {
81
+ machineId = generateUuid();
82
+ localStorage.setItem(MACHINE_ID_STORAGE_KEY, machineId);
83
+ }
84
+ return machineId;
85
+ } catch {
86
+ return generateUuid();
87
+ }
88
+ };
89
+ var generateTokenKey = (domainName) => {
90
+ const domain = normalizeDomainName(domainName);
91
+ const affiliateId = "";
92
+ const loggedInUserId = "";
93
+ const orgId = "";
94
+ return [domain, (/* @__PURE__ */ new Date()).getTime(), affiliateId, loggedInUserId, orgId, "", "", getMachineId()].join("~");
95
+ };
96
+ var buildEncryptedTokenKey = (domainName) => {
97
+ const encryptor = new import_jsencrypt.JSEncrypt();
98
+ encryptor.setPublicKey(RSA_PUBLIC_KEY);
99
+ const encrypted = encryptor.encrypt(generateTokenKey(domainName));
100
+ return typeof encrypted === "string" ? encrypted : "";
101
+ };
67
102
  var PRIMEICONS_LINK_ID = "tfsw-primeicons";
68
103
  var RSA_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
69
104
  MIICITANBgkqhkiG9w0BAQEFAAOCAg4AMIICCQKCAgB0rRSHGZK/FtK15IRfQxtl
@@ -233,7 +268,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
233
268
  if (!searchKeyword.trim()) return [];
234
269
  const url = `${airportSearchApiBaseUrl.replace(/\/$/, "")}/Airport/GetList/${encodeURIComponent(langCode)}/${encodeURIComponent(searchKeyword.trim())}`;
235
270
  try {
236
- const res = await fetch(url);
271
+ const res = await fetch(url, { headers: { Token: buildEncryptedTokenKey(redirectionDomain ?? "") } });
237
272
  if (!res.ok) return [];
238
273
  const data = await res.json();
239
274
  if (Array.isArray(data)) return data;
@@ -243,7 +278,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
243
278
  } catch {
244
279
  return [];
245
280
  }
246
- }, [airportSearchApiBaseUrl, langCode]);
281
+ }, [airportSearchApiBaseUrl, langCode, redirectionDomain]);
247
282
  const getAirlineListBySearch = (0, import_react.useCallback)(async (searchKeyword) => {
248
283
  if (!searchKeyword.trim()) return [];
249
284
  const lang = (langCode ?? "en").toUpperCase();