@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.mjs CHANGED
@@ -38,6 +38,41 @@ var buildEncryptedToken = (domainName) => {
38
38
  const encrypted = encryptor.encrypt(payload);
39
39
  return typeof encrypted === "string" ? encrypted : null;
40
40
  };
41
+ var MACHINE_ID_STORAGE_KEY = "MacId";
42
+ var generateUuid = () => {
43
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
44
+ return crypto.randomUUID();
45
+ }
46
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (c) => {
47
+ const r = Math.random() * 16 | 0;
48
+ return (c === "x" ? r : r & 3 | 8).toString(16);
49
+ });
50
+ };
51
+ var getMachineId = () => {
52
+ try {
53
+ let machineId = localStorage.getItem(MACHINE_ID_STORAGE_KEY);
54
+ if (!machineId) {
55
+ machineId = generateUuid();
56
+ localStorage.setItem(MACHINE_ID_STORAGE_KEY, machineId);
57
+ }
58
+ return machineId;
59
+ } catch {
60
+ return generateUuid();
61
+ }
62
+ };
63
+ var generateTokenKey = (domainName) => {
64
+ const domain = normalizeDomainName(domainName);
65
+ const affiliateId = "";
66
+ const loggedInUserId = "";
67
+ const orgId = "";
68
+ return [domain, (/* @__PURE__ */ new Date()).getTime(), affiliateId, loggedInUserId, orgId, "", "", getMachineId()].join("~");
69
+ };
70
+ var buildEncryptedTokenKey = (domainName) => {
71
+ const encryptor = new JSEncrypt();
72
+ encryptor.setPublicKey(RSA_PUBLIC_KEY);
73
+ const encrypted = encryptor.encrypt(generateTokenKey(domainName));
74
+ return typeof encrypted === "string" ? encrypted : "";
75
+ };
41
76
  var PRIMEICONS_LINK_ID = "tfsw-primeicons";
42
77
  var RSA_PUBLIC_KEY = `-----BEGIN PUBLIC KEY-----
43
78
  MIICITANBgkqhkiG9w0BAQEFAAOCAg4AMIICCQKCAgB0rRSHGZK/FtK15IRfQxtl
@@ -207,7 +242,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
207
242
  if (!searchKeyword.trim()) return [];
208
243
  const url = `${airportSearchApiBaseUrl.replace(/\/$/, "")}/Airport/GetList/${encodeURIComponent(langCode)}/${encodeURIComponent(searchKeyword.trim())}`;
209
244
  try {
210
- const res = await fetch(url);
245
+ const res = await fetch(url, { headers: { Token: buildEncryptedTokenKey(redirectionDomain ?? "") } });
211
246
  if (!res.ok) return [];
212
247
  const data = await res.json();
213
248
  if (Array.isArray(data)) return data;
@@ -217,7 +252,7 @@ function useFlightSearch({ config, ssoUser }, { dropdownSelector }) {
217
252
  } catch {
218
253
  return [];
219
254
  }
220
- }, [airportSearchApiBaseUrl, langCode]);
255
+ }, [airportSearchApiBaseUrl, langCode, redirectionDomain]);
221
256
  const getAirlineListBySearch = useCallback(async (searchKeyword) => {
222
257
  if (!searchKeyword.trim()) return [];
223
258
  const lang = (langCode ?? "en").toUpperCase();