quickhunt-sdk 1.0.0 → 1.0.1-dev.0

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.js CHANGED
@@ -5,38 +5,44 @@
5
5
  function QuickhuntWidget({
6
6
  widgetKey,
7
7
  firstName,
8
- lastName, // string or array of widget keys
8
+ lastName,
9
9
  name,
10
10
  email,
11
11
  uniqueId,
12
12
  projectId,
13
- inAppMessageKey, // string or array
14
- env = "prod" // "dev", "prod"
13
+ inAppMessageKey,
14
+ env = "prod" // "dev" | "prod"
15
15
  }) {
16
- if (typeof window === "undefined") return; // SSR safety
16
+ // SSR safety
17
+ if (typeof window === "undefined") return;
17
18
 
18
- // Determine script URL
19
+ /* --------------------------------
20
+ * Determine script URL
21
+ * -------------------------------- */
19
22
  const scriptUrl =
20
23
  env === "dev"
21
24
  ? "https://devwidget.quickhunt.app/widgetScript.js"
22
25
  : "https://widget.quickhunt.app/widgetScript.js";
23
26
 
24
- // -----------------------------
25
- // 1️⃣ Handle widgetKey(s)
26
- // -----------------------------
27
+ /* --------------------------------
28
+ * 1️⃣ Handle widgetKey(s)
29
+ * -------------------------------- */
27
30
  if (widgetKey) {
28
-
29
31
  window.Quickhunt_Config = window.Quickhunt_Config || [];
30
- // Convert single or multiple keys into an array
32
+
31
33
  const keys = Array.isArray(widgetKey) ? widgetKey : [widgetKey];
34
+
32
35
  const widgetObjects = keys
33
- .filter(key =>
34
- !window.Quickhunt_Config.some(item => item.Quickhunt_Widget_Key === key)
36
+ .filter(
37
+ key =>
38
+ !window.Quickhunt_Config.some(
39
+ item => item.Quickhunt_Widget_Key === key
40
+ )
35
41
  )
36
42
  .map(key => ({
37
- firstName: firstName || "",
38
- lastName: lastName || "",
39
- email: email || "",
43
+ ...(firstName !== undefined && { firstName }),
44
+ ...(lastName !== undefined && { lastName }),
45
+ ...(email !== undefined && { email }),
40
46
  Quickhunt_Widget_Key: key
41
47
  }));
42
48
 
@@ -45,44 +51,64 @@ function QuickhuntWidget({
45
51
  }
46
52
  }
47
53
 
48
- // -----------------------------
49
- // 2️⃣ Handle quickhuntSettings
50
- // -----------------------------
51
- if (projectId || uniqueId || name || email) {
54
+ /* --------------------------------
55
+ * 2️⃣ Handle quickhuntSettings
56
+ * Rules:
57
+ * - undefined ignore (do not overwrite)
58
+ * - "" (empty string) → allowed (explicit clear)
59
+ * - null → allowed (explicit clear)
60
+ * -------------------------------- */
61
+ if (
62
+ projectId !== undefined ||
63
+ uniqueId !== undefined ||
64
+ name !== undefined ||
65
+ email !== undefined
66
+ ) {
52
67
  window.quickhuntSettings = {
53
68
  ...window.quickhuntSettings,
54
- name,
55
- email,
56
- uniqueId,
57
- projectId
69
+
70
+ ...(name !== undefined && { name }),
71
+ ...(email !== undefined && { email }),
72
+ ...(uniqueId !== undefined && { uniqueId }),
73
+ ...(projectId !== undefined && { projectId })
58
74
  };
59
75
  }
60
76
 
61
- // -----------------------------
62
- // 3️⃣ Handle In-App Message(s)
63
- // -----------------------------
77
+ /* --------------------------------
78
+ * 3️⃣ Handle In-App Message(s)
79
+ * -------------------------------- */
64
80
  if (inAppMessageKey) {
65
- window.Quickhunt_In_App_Message_Config = window.Quickhunt_In_App_Message_Config || [];
66
- const keys = Array.isArray(inAppMessageKey) ? inAppMessageKey : [inAppMessageKey];
81
+ window.Quickhunt_In_App_Message_Config =
82
+ window.Quickhunt_In_App_Message_Config || [];
83
+
84
+ const keys = Array.isArray(inAppMessageKey)
85
+ ? inAppMessageKey
86
+ : [inAppMessageKey];
67
87
 
68
88
  keys.forEach(key => {
69
- if (!window.Quickhunt_In_App_Message_Config.some(item => item.Quickhunt_In_App_Message_Key === key)) {
70
- window.Quickhunt_In_App_Message_Config.push({ Quickhunt_In_App_Message_Key: key });
89
+ if (
90
+ !window.Quickhunt_In_App_Message_Config.some(
91
+ item => item.Quickhunt_In_App_Message_Key === key
92
+ )
93
+ ) {
94
+ window.Quickhunt_In_App_Message_Config.push({
95
+ Quickhunt_In_App_Message_Key: key
96
+ });
71
97
  }
72
98
  });
73
99
  }
74
100
 
75
- // -----------------------------
76
- // 4️⃣ Inject main widget script once
77
- // -----------------------------
101
+ /* --------------------------------
102
+ * 4️⃣ Inject main widget script ONCE
103
+ * -------------------------------- */
78
104
  if (!document.getElementById("quickhunt-main-script")) {
79
105
  const script = document.createElement("script");
80
106
  script.id = "quickhunt-main-script";
81
107
  script.src = scriptUrl;
82
108
  script.async = true;
83
109
 
84
- // script.onload = () => console.log("✅ Quickhunt script loaded!");
85
- script.onerror = () => console.error("❌ Quickhunt script failed to load:", scriptUrl);
110
+ script.onerror = () =>
111
+ console.error("❌ Quickhunt script failed to load:", scriptUrl);
86
112
 
87
113
  document.body.appendChild(script);
88
114
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/index.js"],"sourcesContent":["// quickhunt-sdk.js\r\n\r\nexport function QuickhuntWidget({\r\n widgetKey,\r\n firstName,\r\n lastName, // string or array of widget keys\r\n name,\r\n email,\r\n uniqueId,\r\n projectId,\r\n inAppMessageKey, // string or array\r\n env = \"prod\" // \"dev\", \"prod\"\r\n}) {\r\n if (typeof window === \"undefined\") return; // SSR safety\r\n\r\n // Determine script URL\r\n const scriptUrl =\r\n env === \"dev\"\r\n ? \"https://devwidget.quickhunt.app/widgetScript.js\"\r\n : \"https://widget.quickhunt.app/widgetScript.js\";\r\n\r\n // -----------------------------\r\n // 1️⃣ Handle widgetKey(s)\r\n // -----------------------------\r\n if (widgetKey) {\r\n\r\n window.Quickhunt_Config = window.Quickhunt_Config || [];\r\n // Convert single or multiple keys into an array\r\n const keys = Array.isArray(widgetKey) ? widgetKey : [widgetKey];\r\n const widgetObjects = keys\r\n .filter(key =>\r\n !window.Quickhunt_Config.some(item => item.Quickhunt_Widget_Key === key)\r\n )\r\n .map(key => ({\r\n firstName: firstName || \"\",\r\n lastName: lastName || \"\",\r\n email: email || \"\",\r\n Quickhunt_Widget_Key: key\r\n }));\r\n\r\n if (widgetObjects.length > 0) {\r\n window.Quickhunt_Config.push(...widgetObjects);\r\n }\r\n }\r\n\r\n // -----------------------------\r\n // 2️⃣ Handle quickhuntSettings\r\n // -----------------------------\r\n if (projectId || uniqueId || name || email) {\r\n window.quickhuntSettings = {\r\n ...window.quickhuntSettings,\r\n name,\r\n email,\r\n uniqueId,\r\n projectId\r\n };\r\n }\r\n\r\n // -----------------------------\r\n // 3️⃣ Handle In-App Message(s)\r\n // -----------------------------\r\n if (inAppMessageKey) {\r\n window.Quickhunt_In_App_Message_Config = window.Quickhunt_In_App_Message_Config || [];\r\n const keys = Array.isArray(inAppMessageKey) ? inAppMessageKey : [inAppMessageKey];\r\n\r\n keys.forEach(key => {\r\n if (!window.Quickhunt_In_App_Message_Config.some(item => item.Quickhunt_In_App_Message_Key === key)) {\r\n window.Quickhunt_In_App_Message_Config.push({ Quickhunt_In_App_Message_Key: key });\r\n }\r\n });\r\n }\r\n\r\n // -----------------------------\r\n // 4️⃣ Inject main widget script once\r\n // -----------------------------\r\n if (!document.getElementById(\"quickhunt-main-script\")) {\r\n const script = document.createElement(\"script\");\r\n script.id = \"quickhunt-main-script\";\r\n script.src = scriptUrl;\r\n script.async = true;\r\n\r\n // script.onload = () => console.log(\"✅ Quickhunt script loaded!\");\r\n script.onerror = () => console.error(\"❌ Quickhunt script failed to load:\", scriptUrl);\r\n\r\n document.body.appendChild(script);\r\n } else {\r\n // console.log(\"⚠️ Quickhunt main script already loaded\");\r\n }\r\n}\r\n"],"names":[],"mappings":";;AAAA;AACA;AACO,SAAS,eAAe,CAAC;AAChC,EAAE,SAAS;AACX,EAAE,SAAS;AACX,EAAE,QAAQ;AACV,EAAE,IAAI;AACN,EAAE,KAAK;AACP,EAAE,QAAQ;AACV,EAAE,SAAS;AACX,EAAE,eAAe;AACjB,EAAE,GAAG,GAAG,MAAM;AACd,CAAC,EAAE;AACH,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,OAAO;AAC5C;AACA;AACA,EAA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AAe,EAAE;AACvB,IAAI,MAAM,CAAC,+BAA+B,GAAG,MAAM,CAAC,+BAA+B,IAAI,EAAE,CAAC;AAC1F,IAAI,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,eAAe,GAAG,CAAC,eAAe,CAAC,CAAC;AACtF;AACA,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI;AACxB,MAAM,IAAI,CAAC,MAAM,CAAC,+BAA+B,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,4BAA4B,KAAK,GAAG,CAAC,EAAE;AAC3G,QAAQ,MAAM,CAAC,+BAA+B,CAAC,IAAI,CAAC,EAAE,4BAA4B,EAAE,GAAG,EAAE,CAAC,CAAC;AAC3F,MAAM,CAAC;AACP,IAAI,CAAC,CAAC,CAAC;AACP,EAAE,CAAC;AACH;AACA;AACA;AACA;AACA,EAAE,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,uBAAuB,CAAC,EAAE;AACzD,IAAI,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AACpD,IAAI,MAAM,CAAC,EAAE,GAAG,uBAAuB,CAAC;AACxC,IAAI,MAAM,CAAC,GAAG,GAAG,SAAS,CAAC;AAC3B,IAAI,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;AACxB;AACA;AACA,IAAI,MAAM,CAAC,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,SAAS,CAAC,CAAC;AAC1F;AACA,IAAI,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACtC,EAAE,CAEC;AACH;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/index.js"],"sourcesContent":["// quickhunt-sdk.js\r\n\r\nexport function QuickhuntWidget({\r\n widgetKey,\r\n firstName,\r\n lastName,\r\n name,\r\n email,\r\n uniqueId,\r\n projectId,\r\n inAppMessageKey,\r\n env = \"prod\" // \"dev\" | \"prod\"\r\n}) {\r\n // SSR safety\r\n if (typeof window === \"undefined\") return;\r\n\r\n /* --------------------------------\r\n * Determine script URL\r\n * -------------------------------- */\r\n const scriptUrl =\r\n env === \"dev\"\r\n ? \"https://devwidget.quickhunt.app/widgetScript.js\"\r\n : \"https://widget.quickhunt.app/widgetScript.js\";\r\n\r\n /* --------------------------------\r\n * 1️⃣ Handle widgetKey(s)\r\n * -------------------------------- */\r\n if (widgetKey) {\r\n window.Quickhunt_Config = window.Quickhunt_Config || [];\r\n\r\n const keys = Array.isArray(widgetKey) ? widgetKey : [widgetKey];\r\n\r\n const widgetObjects = keys\r\n .filter(\r\n key =>\r\n !window.Quickhunt_Config.some(\r\n item => item.Quickhunt_Widget_Key === key\r\n )\r\n )\r\n .map(key => ({\r\n ...(firstName !== undefined && { firstName }),\r\n ...(lastName !== undefined && { lastName }),\r\n ...(email !== undefined && { email }),\r\n Quickhunt_Widget_Key: key\r\n }));\r\n\r\n if (widgetObjects.length > 0) {\r\n window.Quickhunt_Config.push(...widgetObjects);\r\n }\r\n }\r\n\r\n /* --------------------------------\r\n * 2️⃣ Handle quickhuntSettings\r\n * Rules:\r\n * - undefined → ignore (do not overwrite)\r\n * - \"\" (empty string) → allowed (explicit clear)\r\n * - null → allowed (explicit clear)\r\n * -------------------------------- */\r\n if (\r\n projectId !== undefined ||\r\n uniqueId !== undefined ||\r\n name !== undefined ||\r\n email !== undefined\r\n ) {\r\n window.quickhuntSettings = {\r\n ...window.quickhuntSettings,\r\n\r\n ...(name !== undefined && { name }),\r\n ...(email !== undefined && { email }),\r\n ...(uniqueId !== undefined && { uniqueId }),\r\n ...(projectId !== undefined && { projectId })\r\n };\r\n }\r\n\r\n /* --------------------------------\r\n * 3️⃣ Handle In-App Message(s)\r\n * -------------------------------- */\r\n if (inAppMessageKey) {\r\n window.Quickhunt_In_App_Message_Config =\r\n window.Quickhunt_In_App_Message_Config || [];\r\n\r\n const keys = Array.isArray(inAppMessageKey)\r\n ? inAppMessageKey\r\n : [inAppMessageKey];\r\n\r\n keys.forEach(key => {\r\n if (\r\n !window.Quickhunt_In_App_Message_Config.some(\r\n item => item.Quickhunt_In_App_Message_Key === key\r\n )\r\n ) {\r\n window.Quickhunt_In_App_Message_Config.push({\r\n Quickhunt_In_App_Message_Key: key\r\n });\r\n }\r\n });\r\n }\r\n\r\n /* --------------------------------\r\n * 4️⃣ Inject main widget script ONCE\r\n * -------------------------------- */\r\n if (!document.getElementById(\"quickhunt-main-script\")) {\r\n const script = document.createElement(\"script\");\r\n script.id = \"quickhunt-main-script\";\r\n script.src = scriptUrl;\r\n script.async = true;\r\n\r\n script.onerror = () =>\r\n console.error(\"❌ Quickhunt script failed to load:\", scriptUrl);\r\n\r\n document.body.appendChild(script);\r\n }\r\n}\r\n"],"names":[],"mappings":";;AAAA;AACA;AACO,SAAS,eAAe,CAAC;AAChC,EAAE,SAAS;AACX,EAAE,SAAS;AACX,EAAE,QAAQ;AACV,EAAE,IAAI;AACN,EAAE,KAAK;AACP,EAAE,QAAQ;AACV,EAAE,SAAS;AACX,EAAE,eAAe;AACjB,EAAE,GAAG,GAAG,MAAM;AACd,CAAC,EAAE;AACH;AACA,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,OAAO;AAC5C;AACA;AACA;AACA;AACA,EAAE,MAAM,SAAS;AACjB,IAAI,GAAG,KAAK,KAAK;AACjB,QAAQ,iDAAiD;AACzD,QAAQ,8CAA8C,CAAC;AACvD;AACA;AACA;AACA;AACA,EAAE,IAAI,SAAS,EAAE;AACjB,IAAI,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,IAAI,EAAE,CAAC;AAC5D;AACA,IAAI,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS,CAAC,CAAC;AACpE;AACA,IAAI,MAAM,aAAa,GAAG,IAAI;AAC9B,OAAO,MAAM;AACb,QAAQ,G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AI,MAAM,CAAC,+BAA+B;AAC1C,MAAM,MAAM,CAAC,+BAA+B,IAAI,EAAE,CAAC;AACnD;AACA,IAAI,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,eAAe,CAAC;AAC/C,QAAQ,eAAe;AACvB,QAAQ,CAAC,eAAe,CAAC,CAAC;AAC1B;AACA,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI;AACxB,MAAM;AACN,QAAQ,CAAC,MAAM,CAAC,+BAA+B,CAAC,IAAI;AACpD,UAAU,IAAI,IAAI,IAAI,CAAC,4BAA4B,KAAK,GAAG;AAC3D,SAAS;AACT,QAAQ;AACR,QAAQ,MAAM,CAAC,+BAA+B,CAAC,IAAI,CAAC;AACpD,UAAU,4BAA4B,EAAE,GAAG;AAC3C,SAAS,CAAC,CAAC;AACX,MAAM,CAAC;AACP,IAAI,CAAC,CAAC,CAAC;AACP,EAAE,CAAC;AACH;AACA;AACA;AACA;AACA,EAAE,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,uBAAuB,CAAC,EAAE;AACzD,IAAI,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AACpD,IAAI,MAAM,CAAC,EAAE,GAAG,uBAAuB,CAAC;AACxC,IAAI,MAAM,CAAC,GAAG,GAAG,SAAS,CAAC;AAC3B,IAAI,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;AACxB;AACA,IAAI,MAAM,CAAC,OAAO,GAAG;AACrB,MAAM,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,SAAS,CAAC,CAAC;AACrE;AACA,IAAI,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACtC,EAAE,CAAC;AACH;;;;"}
package/dist/index.esm.js CHANGED
@@ -3,38 +3,44 @@
3
3
  function QuickhuntWidget({
4
4
  widgetKey,
5
5
  firstName,
6
- lastName, // string or array of widget keys
6
+ lastName,
7
7
  name,
8
8
  email,
9
9
  uniqueId,
10
10
  projectId,
11
- inAppMessageKey, // string or array
12
- env = "prod" // "dev", "prod"
11
+ inAppMessageKey,
12
+ env = "prod" // "dev" | "prod"
13
13
  }) {
14
- if (typeof window === "undefined") return; // SSR safety
14
+ // SSR safety
15
+ if (typeof window === "undefined") return;
15
16
 
16
- // Determine script URL
17
+ /* --------------------------------
18
+ * Determine script URL
19
+ * -------------------------------- */
17
20
  const scriptUrl =
18
21
  env === "dev"
19
22
  ? "https://devwidget.quickhunt.app/widgetScript.js"
20
23
  : "https://widget.quickhunt.app/widgetScript.js";
21
24
 
22
- // -----------------------------
23
- // 1️⃣ Handle widgetKey(s)
24
- // -----------------------------
25
+ /* --------------------------------
26
+ * 1️⃣ Handle widgetKey(s)
27
+ * -------------------------------- */
25
28
  if (widgetKey) {
26
-
27
29
  window.Quickhunt_Config = window.Quickhunt_Config || [];
28
- // Convert single or multiple keys into an array
30
+
29
31
  const keys = Array.isArray(widgetKey) ? widgetKey : [widgetKey];
32
+
30
33
  const widgetObjects = keys
31
- .filter(key =>
32
- !window.Quickhunt_Config.some(item => item.Quickhunt_Widget_Key === key)
34
+ .filter(
35
+ key =>
36
+ !window.Quickhunt_Config.some(
37
+ item => item.Quickhunt_Widget_Key === key
38
+ )
33
39
  )
34
40
  .map(key => ({
35
- firstName: firstName || "",
36
- lastName: lastName || "",
37
- email: email || "",
41
+ ...(firstName !== undefined && { firstName }),
42
+ ...(lastName !== undefined && { lastName }),
43
+ ...(email !== undefined && { email }),
38
44
  Quickhunt_Widget_Key: key
39
45
  }));
40
46
 
@@ -43,44 +49,64 @@ function QuickhuntWidget({
43
49
  }
44
50
  }
45
51
 
46
- // -----------------------------
47
- // 2️⃣ Handle quickhuntSettings
48
- // -----------------------------
49
- if (projectId || uniqueId || name || email) {
52
+ /* --------------------------------
53
+ * 2️⃣ Handle quickhuntSettings
54
+ * Rules:
55
+ * - undefined ignore (do not overwrite)
56
+ * - "" (empty string) → allowed (explicit clear)
57
+ * - null → allowed (explicit clear)
58
+ * -------------------------------- */
59
+ if (
60
+ projectId !== undefined ||
61
+ uniqueId !== undefined ||
62
+ name !== undefined ||
63
+ email !== undefined
64
+ ) {
50
65
  window.quickhuntSettings = {
51
66
  ...window.quickhuntSettings,
52
- name,
53
- email,
54
- uniqueId,
55
- projectId
67
+
68
+ ...(name !== undefined && { name }),
69
+ ...(email !== undefined && { email }),
70
+ ...(uniqueId !== undefined && { uniqueId }),
71
+ ...(projectId !== undefined && { projectId })
56
72
  };
57
73
  }
58
74
 
59
- // -----------------------------
60
- // 3️⃣ Handle In-App Message(s)
61
- // -----------------------------
75
+ /* --------------------------------
76
+ * 3️⃣ Handle In-App Message(s)
77
+ * -------------------------------- */
62
78
  if (inAppMessageKey) {
63
- window.Quickhunt_In_App_Message_Config = window.Quickhunt_In_App_Message_Config || [];
64
- const keys = Array.isArray(inAppMessageKey) ? inAppMessageKey : [inAppMessageKey];
79
+ window.Quickhunt_In_App_Message_Config =
80
+ window.Quickhunt_In_App_Message_Config || [];
81
+
82
+ const keys = Array.isArray(inAppMessageKey)
83
+ ? inAppMessageKey
84
+ : [inAppMessageKey];
65
85
 
66
86
  keys.forEach(key => {
67
- if (!window.Quickhunt_In_App_Message_Config.some(item => item.Quickhunt_In_App_Message_Key === key)) {
68
- window.Quickhunt_In_App_Message_Config.push({ Quickhunt_In_App_Message_Key: key });
87
+ if (
88
+ !window.Quickhunt_In_App_Message_Config.some(
89
+ item => item.Quickhunt_In_App_Message_Key === key
90
+ )
91
+ ) {
92
+ window.Quickhunt_In_App_Message_Config.push({
93
+ Quickhunt_In_App_Message_Key: key
94
+ });
69
95
  }
70
96
  });
71
97
  }
72
98
 
73
- // -----------------------------
74
- // 4️⃣ Inject main widget script once
75
- // -----------------------------
99
+ /* --------------------------------
100
+ * 4️⃣ Inject main widget script ONCE
101
+ * -------------------------------- */
76
102
  if (!document.getElementById("quickhunt-main-script")) {
77
103
  const script = document.createElement("script");
78
104
  script.id = "quickhunt-main-script";
79
105
  script.src = scriptUrl;
80
106
  script.async = true;
81
107
 
82
- // script.onload = () => console.log("✅ Quickhunt script loaded!");
83
- script.onerror = () => console.error("❌ Quickhunt script failed to load:", scriptUrl);
108
+ script.onerror = () =>
109
+ console.error("❌ Quickhunt script failed to load:", scriptUrl);
84
110
 
85
111
  document.body.appendChild(script);
86
112
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.esm.js","sources":["../src/index.js"],"sourcesContent":["// quickhunt-sdk.js\r\n\r\nexport function QuickhuntWidget({\r\n widgetKey,\r\n firstName,\r\n lastName, // string or array of widget keys\r\n name,\r\n email,\r\n uniqueId,\r\n projectId,\r\n inAppMessageKey, // string or array\r\n env = \"prod\" // \"dev\", \"prod\"\r\n}) {\r\n if (typeof window === \"undefined\") return; // SSR safety\r\n\r\n // Determine script URL\r\n const scriptUrl =\r\n env === \"dev\"\r\n ? \"https://devwidget.quickhunt.app/widgetScript.js\"\r\n : \"https://widget.quickhunt.app/widgetScript.js\";\r\n\r\n // -----------------------------\r\n // 1️⃣ Handle widgetKey(s)\r\n // -----------------------------\r\n if (widgetKey) {\r\n\r\n window.Quickhunt_Config = window.Quickhunt_Config || [];\r\n // Convert single or multiple keys into an array\r\n const keys = Array.isArray(widgetKey) ? widgetKey : [widgetKey];\r\n const widgetObjects = keys\r\n .filter(key =>\r\n !window.Quickhunt_Config.some(item => item.Quickhunt_Widget_Key === key)\r\n )\r\n .map(key => ({\r\n firstName: firstName || \"\",\r\n lastName: lastName || \"\",\r\n email: email || \"\",\r\n Quickhunt_Widget_Key: key\r\n }));\r\n\r\n if (widgetObjects.length > 0) {\r\n window.Quickhunt_Config.push(...widgetObjects);\r\n }\r\n }\r\n\r\n // -----------------------------\r\n // 2️⃣ Handle quickhuntSettings\r\n // -----------------------------\r\n if (projectId || uniqueId || name || email) {\r\n window.quickhuntSettings = {\r\n ...window.quickhuntSettings,\r\n name,\r\n email,\r\n uniqueId,\r\n projectId\r\n };\r\n }\r\n\r\n // -----------------------------\r\n // 3️⃣ Handle In-App Message(s)\r\n // -----------------------------\r\n if (inAppMessageKey) {\r\n window.Quickhunt_In_App_Message_Config = window.Quickhunt_In_App_Message_Config || [];\r\n const keys = Array.isArray(inAppMessageKey) ? inAppMessageKey : [inAppMessageKey];\r\n\r\n keys.forEach(key => {\r\n if (!window.Quickhunt_In_App_Message_Config.some(item => item.Quickhunt_In_App_Message_Key === key)) {\r\n window.Quickhunt_In_App_Message_Config.push({ Quickhunt_In_App_Message_Key: key });\r\n }\r\n });\r\n }\r\n\r\n // -----------------------------\r\n // 4️⃣ Inject main widget script once\r\n // -----------------------------\r\n if (!document.getElementById(\"quickhunt-main-script\")) {\r\n const script = document.createElement(\"script\");\r\n script.id = \"quickhunt-main-script\";\r\n script.src = scriptUrl;\r\n script.async = true;\r\n\r\n // script.onload = () => console.log(\"✅ Quickhunt script loaded!\");\r\n script.onerror = () => console.error(\"❌ Quickhunt script failed to load:\", scriptUrl);\r\n\r\n document.body.appendChild(script);\r\n } else {\r\n // console.log(\"⚠️ Quickhunt main script already loaded\");\r\n }\r\n}\r\n"],"names":[],"mappings":"AAAA;AACA;AACO,SAAS,eAAe,CAAC;AAChC,EAAE,SAAS;AACX,EAAE,SAAS;AACX,EAAE,QAAQ;AACV,EAAE,IAAI;AACN,EAAE,KAAK;AACP,EAAE,QAAQ;AACV,EAAE,SAAS;AACX,EAAE,eAAe;AACjB,EAAE,GAAG,GAAG,MAAM;AACd,CAAC,EAAE;AACH,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,OAAO;AAC5C;AACA;AACA,EAAE,MAAM,SAAS;AACjB,IAAI,GAAG,KAAK,KAAK;AACjB,QAAQ,iDAAiD;AACzD,QAAQ,8CAA8C,CAAC;AACvD;AACA;AACA;AACA;AACA,EAAE,IAAI,SAAS,EAAE;AACjB;AACA,IAAI,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,IAAI,EAAE,CAAC;AAC5D;AACA,IAAI,MAAM,IAAI,GA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AAM,IAAI,CAAC,MAAM,CAAC,+BAA+B,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,4BAA4B,KAAK,GAAG,CAAC,EAAE;AAC3G,QAAQ,MAAM,CAAC,+BAA+B,CAAC,IAAI,CAAC,EAAE,4BAA4B,EAAE,GAAG,EAAE,CAAC,CAAC;AAC3F,MAAM,CAAC;AACP,IAAI,CAAC,CAAC,CAAC;AACP,EAAE,CAAC;AACH;AACA;AACA;AACA;AACA,EAAE,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,uBAAuB,CAAC,EAAE;AACzD,IAAI,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AACpD,IAAI,MAAM,CAAC,EAAE,GAAG,uBAAuB,CAAC;AACxC,IAAI,MAAM,CAAC,GAAG,GAAG,SAAS,CAAC;AAC3B,IAAI,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;AACxB;AACA;AACA,IAAI,MAAM,CAAC,OAAO,GAAG,MAAM,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,SAAS,CAAC,CAAC;AAC1F;AACA,IAAI,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACtC,EAAE,CAEC;AACH;;;;"}
1
+ {"version":3,"file":"index.esm.js","sources":["../src/index.js"],"sourcesContent":["// quickhunt-sdk.js\r\n\r\nexport function QuickhuntWidget({\r\n widgetKey,\r\n firstName,\r\n lastName,\r\n name,\r\n email,\r\n uniqueId,\r\n projectId,\r\n inAppMessageKey,\r\n env = \"prod\" // \"dev\" | \"prod\"\r\n}) {\r\n // SSR safety\r\n if (typeof window === \"undefined\") return;\r\n\r\n /* --------------------------------\r\n * Determine script URL\r\n * -------------------------------- */\r\n const scriptUrl =\r\n env === \"dev\"\r\n ? \"https://devwidget.quickhunt.app/widgetScript.js\"\r\n : \"https://widget.quickhunt.app/widgetScript.js\";\r\n\r\n /* --------------------------------\r\n * 1️⃣ Handle widgetKey(s)\r\n * -------------------------------- */\r\n if (widgetKey) {\r\n window.Quickhunt_Config = window.Quickhunt_Config || [];\r\n\r\n const keys = Array.isArray(widgetKey) ? widgetKey : [widgetKey];\r\n\r\n const widgetObjects = keys\r\n .filter(\r\n key =>\r\n !window.Quickhunt_Config.some(\r\n item => item.Quickhunt_Widget_Key === key\r\n )\r\n )\r\n .map(key => ({\r\n ...(firstName !== undefined && { firstName }),\r\n ...(lastName !== undefined && { lastName }),\r\n ...(email !== undefined && { email }),\r\n Quickhunt_Widget_Key: key\r\n }));\r\n\r\n if (widgetObjects.length > 0) {\r\n window.Quickhunt_Config.push(...widgetObjects);\r\n }\r\n }\r\n\r\n /* --------------------------------\r\n * 2️⃣ Handle quickhuntSettings\r\n * Rules:\r\n * - undefined → ignore (do not overwrite)\r\n * - \"\" (empty string) → allowed (explicit clear)\r\n * - null → allowed (explicit clear)\r\n * -------------------------------- */\r\n if (\r\n projectId !== undefined ||\r\n uniqueId !== undefined ||\r\n name !== undefined ||\r\n email !== undefined\r\n ) {\r\n window.quickhuntSettings = {\r\n ...window.quickhuntSettings,\r\n\r\n ...(name !== undefined && { name }),\r\n ...(email !== undefined && { email }),\r\n ...(uniqueId !== undefined && { uniqueId }),\r\n ...(projectId !== undefined && { projectId })\r\n };\r\n }\r\n\r\n /* --------------------------------\r\n * 3️⃣ Handle In-App Message(s)\r\n * -------------------------------- */\r\n if (inAppMessageKey) {\r\n window.Quickhunt_In_App_Message_Config =\r\n window.Quickhunt_In_App_Message_Config || [];\r\n\r\n const keys = Array.isArray(inAppMessageKey)\r\n ? inAppMessageKey\r\n : [inAppMessageKey];\r\n\r\n keys.forEach(key => {\r\n if (\r\n !window.Quickhunt_In_App_Message_Config.some(\r\n item => item.Quickhunt_In_App_Message_Key === key\r\n )\r\n ) {\r\n window.Quickhunt_In_App_Message_Config.push({\r\n Quickhunt_In_App_Message_Key: key\r\n });\r\n }\r\n });\r\n }\r\n\r\n /* --------------------------------\r\n * 4️⃣ Inject main widget script ONCE\r\n * -------------------------------- */\r\n if (!document.getElementById(\"quickhunt-main-script\")) {\r\n const script = document.createElement(\"script\");\r\n script.id = \"quickhunt-main-script\";\r\n script.src = scriptUrl;\r\n script.async = true;\r\n\r\n script.onerror = () =>\r\n console.error(\"❌ Quickhunt script failed to load:\", scriptUrl);\r\n\r\n document.body.appendChild(script);\r\n }\r\n}\r\n"],"names":[],"mappings":"AAAA;AACA;AACO,SAAS,eAAe,CAAC;AAChC,EAAE,SAAS;AACX,EAAE,SAAS;AACX,EAAE,QAAQ;AACV,EAAE,IAAI;AACN,EAAE,KAAK;AACP,EAAE,QAAQ;AACV,EAAE,SAAS;AACX,EAAE,eAAe;AACjB,EAAE,GAAG,GAAG,MAAM;AACd,CAAC,EAAE;AACH;AACA,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,OAAO;AAC5C;AACA;AACA;AACA;AACA,EAAE,MAAM,SAAS;AACjB,IAAI,GAAG,KAAK,KAAK;AACjB,QAAQ,iDAAiD;AACzD,QAAQ,8CAA8C,CAAC;AACvD;AACA;AACA;AACA;AACA,EAAE,IAAI,SAAS,EAAE;AACjB,IAAI,MAAM,CAAC,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,IAAI,EAAE,CAAC;AAC5D;AACA,IAAI,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,GAAG,CAAC,SAAS,CAAC,CAAC;AACpE;AACA,IAAI,MAAM,aAAa,GAAG,IAAI;AAC9B,OAAO,MAAM;AACb,QAAQ,GAAG;AACX,UAAU,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI;AACvC,YAAY,IAAI,IAAI,IAAI,CAAC,oBAAoB,KAAK,GAAG;AACrD,WAAW;AACX,OAAO;AACP,OAAO,GAAG,CAAC,GAAG,KAAK;AACnB,QAAQ,IAAI,SAAS,KAAK,SAAS,IAAI,EAAE,SAAS,EAAE,CAAC;AACrD,QAAQ,IAAI,QAAQ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ACxB,MAAM;AACN,QAAQ,CAAC,MAAM,CAAC,+BAA+B,CAAC,IAAI;AACpD,UAAU,IAAI,IAAI,IAAI,CAAC,4BAA4B,KAAK,GAAG;AAC3D,SAAS;AACT,QAAQ;AACR,QAAQ,MAAM,CAAC,+BAA+B,CAAC,IAAI,CAAC;AACpD,UAAU,4BAA4B,EAAE,GAAG;AAC3C,SAAS,CAAC,CAAC;AACX,MAAM,CAAC;AACP,IAAI,CAAC,CAAC,CAAC;AACP,EAAE,CAAC;AACH;AACA;AACA;AACA;AACA,EAAE,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,uBAAuB,CAAC,EAAE;AACzD,IAAI,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;AACpD,IAAI,MAAM,CAAC,EAAE,GAAG,uBAAuB,CAAC;AACxC,IAAI,MAAM,CAAC,GAAG,GAAG,SAAS,CAAC;AAC3B,IAAI,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;AACxB;AACA,IAAI,MAAM,CAAC,OAAO,GAAG;AACrB,MAAM,OAAO,CAAC,KAAK,CAAC,oCAAoC,EAAE,SAAS,CAAC,CAAC;AACrE;AACA,IAAI,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;AACtC,EAAE,CAAC;AACH;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quickhunt-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.0.1-dev.0",
4
4
  "description": "Quickhunt SDK for React",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",