@bikdotai/bik-widgets 1.0.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.
Files changed (206) hide show
  1. package/.eslintrc +22 -0
  2. package/.eslintrc.js +19 -0
  3. package/.github/workflows/main.yml +293 -0
  4. package/.prettierignore +13 -0
  5. package/.prettierrc +10 -0
  6. package/README.md +128 -0
  7. package/cypress/apiHelper/endpoints.ts +21 -0
  8. package/cypress/apiHelper/executor.ts +42 -0
  9. package/cypress/e2e/bottomDrawer.cy.ts +49 -0
  10. package/cypress/e2e/directReward.cy.ts +67 -0
  11. package/cypress/e2e/scratchTheCard.cy.ts +68 -0
  12. package/cypress/e2e/stw.cy.ts +82 -0
  13. package/cypress/e2e/waRedirection.cy.ts +46 -0
  14. package/cypress/fixtures/payloads.ts +330 -0
  15. package/cypress/support/commands.ts +37 -0
  16. package/cypress/support/e2e.ts +20 -0
  17. package/cypress.staging.config.ts +23 -0
  18. package/jsconfig.json +6 -0
  19. package/localtest.sh +10 -0
  20. package/log-server.js +86 -0
  21. package/package.json +79 -0
  22. package/postcss.config.js +8 -0
  23. package/src/Globals.d.ts +2 -0
  24. package/src/assets/lottie/santa.json +11722 -0
  25. package/src/assets/svg/CalendarClockIcon.tsx +30 -0
  26. package/src/assets/svg/CalendarIcon.tsx +24 -0
  27. package/src/assets/svg/CheckIcon.tsx +17 -0
  28. package/src/assets/svg/ChevronIcon.tsx +21 -0
  29. package/src/assets/svg/Close.tsx +39 -0
  30. package/src/assets/svg/Confetti.tsx +140 -0
  31. package/src/assets/svg/Copy.tsx +26 -0
  32. package/src/assets/svg/DropdownCheckIcon.tsx +35 -0
  33. package/src/assets/svg/ErrorIcon.tsx +27 -0
  34. package/src/assets/svg/RadioIcon.tsx +25 -0
  35. package/src/assets/svg/UncheckedCheckboxIcon.tsx +28 -0
  36. package/src/assets/svg/UncheckedRadioIcon.tsx +26 -0
  37. package/src/assets/svg/info.tsx +30 -0
  38. package/src/assets/svg/qrcode.svg +14 -0
  39. package/src/bootstrap.tsx +8 -0
  40. package/src/components/CtaCard/index.tsx +37 -0
  41. package/src/components/CtaCard/preview.module.css +32 -0
  42. package/src/components/CtaCard/style.module.css +32 -0
  43. package/src/components/EmailInput/emailInputBox.tsx +95 -0
  44. package/src/components/Fab/index.tsx +224 -0
  45. package/src/components/Fab/preview.module.css +28 -0
  46. package/src/components/Fab/style.module.css +37 -0
  47. package/src/components/Icons/Call.tsx +26 -0
  48. package/src/components/Icons/Cross.tsx +24 -0
  49. package/src/components/Icons/Gmail.tsx +61 -0
  50. package/src/components/Icons/Instagram.tsx +60 -0
  51. package/src/components/Icons/LiveChat.tsx +43 -0
  52. package/src/components/Icons/Messenger.tsx +57 -0
  53. package/src/components/Icons/Send.tsx +22 -0
  54. package/src/components/Icons/Whatsapp.tsx +24 -0
  55. package/src/components/Shimmer/index.tsx +12 -0
  56. package/src/components/Shimmer/style.module.css +37 -0
  57. package/src/components/SmsInput/smsInputBox.tsx +135 -0
  58. package/src/components/UserDetailsV2/userDetailsV2.desktop.module.css +52 -0
  59. package/src/components/UserDetailsV2/userDetailsV2.mobile.module.css +52 -0
  60. package/src/components/UserDetailsV2/userDetailsV2.module.css +81 -0
  61. package/src/components/UserDetailsV2/userDetailsV2.tsx +527 -0
  62. package/src/components/WhatsappInput/Spinner.tsx +26 -0
  63. package/src/components/WhatsappInput/whatsappInput.module.css +106 -0
  64. package/src/components/WhatsappInput/whatsappInputBox.tsx +155 -0
  65. package/src/components/WhatsappInput/whatsappInputPreviewDesktop.module.css +71 -0
  66. package/src/components/WhatsappInput/whatsappInputPreviewMobile.module.css +65 -0
  67. package/src/components/checkbox/checkbox.module.css +19 -0
  68. package/src/components/checkbox/checkbox.tsx +88 -0
  69. package/src/components/countryCodePicker/countriesDropdown.module.css +77 -0
  70. package/src/components/countryCodePicker/countriesDropdown.tsx +81 -0
  71. package/src/components/couponDetails/coupon.module.css +208 -0
  72. package/src/components/couponDetails/coupon.tsx +210 -0
  73. package/src/components/couponDetails/couponPreviewDesktop.module.css +158 -0
  74. package/src/components/couponDetails/couponPreviewMobile.module.css +164 -0
  75. package/src/components/index.ts +3 -0
  76. package/src/components/inputComponents/Checkbox.module.css +197 -0
  77. package/src/components/inputComponents/Checkbox.tsx +85 -0
  78. package/src/components/inputComponents/DatePicker.module.css +565 -0
  79. package/src/components/inputComponents/DatePicker.tsx +278 -0
  80. package/src/components/inputComponents/Dropdown.module.css +796 -0
  81. package/src/components/inputComponents/Dropdown.tsx +630 -0
  82. package/src/components/inputComponents/InputBox.module.css +401 -0
  83. package/src/components/inputComponents/InputBox.tsx +209 -0
  84. package/src/components/selectedCountry/selectedCountry.module.css +76 -0
  85. package/src/components/selectedCountry/selectedCountry.tsx +76 -0
  86. package/src/components/selectedCountry/selectedCountryPreviewDesktop.module.css +56 -0
  87. package/src/components/selectedCountry/selectedCountryPreviewMobile.module.css +57 -0
  88. package/src/components/userDetailsForm/RenderCustomFields.tsx +333 -0
  89. package/src/components/userDetailsForm/userDetailsForm.tsx +675 -0
  90. package/src/hooks/index.ts +4 -0
  91. package/src/hooks/useExitIntent.ts +452 -0
  92. package/src/hooks/useIsMobile.tsx +21 -0
  93. package/src/hooks/useMessageEvent.ts +8 -0
  94. package/src/hooks/useTriggeredIntentDetails.ts +43 -0
  95. package/src/hooks/useUrlListerner.ts +30 -0
  96. package/src/hooks/useWebSocketLogger.ts +59 -0
  97. package/src/hooks/useWindowEvent.ts +8 -0
  98. package/src/icons/copyIcon.tsx +26 -0
  99. package/src/icons/crossIconDesktop.tsx +20 -0
  100. package/src/icons/crossIconMobile.tsx +20 -0
  101. package/src/index.html +30 -0
  102. package/src/index.ts +32 -0
  103. package/src/index.tsx +1 -0
  104. package/src/repo/widgetRepo.ts +21 -0
  105. package/src/types/customFields.ts +73 -0
  106. package/src/utilities/cookie.ts +70 -0
  107. package/src/utilities/customFieldTypeMapping.ts +67 -0
  108. package/src/utilities/customFieldValidation.ts +201 -0
  109. package/src/utilities/encryption.ts +21 -0
  110. package/src/utilities/exitIntentUtils.ts +31 -0
  111. package/src/utilities/global.css +11 -0
  112. package/src/utilities/languageUtilities.ts +235 -0
  113. package/src/utilities/localRunner.js +26 -0
  114. package/src/utilities/localRunner.ts +27 -0
  115. package/src/utilities/localStorage.ts +40 -0
  116. package/src/utilities/script.tsx +15 -0
  117. package/src/utilities/stringUtils.ts +5 -0
  118. package/src/utilities/styleUtils.ts +134 -0
  119. package/src/utilities/variables.ts +11 -0
  120. package/src/utilities/widgetUtils.js +342 -0
  121. package/src/utilities/widgetUtils.ts +313 -0
  122. package/src/widgets/BottomDrawer/config.ts +41 -0
  123. package/src/widgets/BottomDrawer/index.tsx +116 -0
  124. package/src/widgets/BottomDrawer/modal.tsx +286 -0
  125. package/src/widgets/BottomDrawer/preview.module.css +122 -0
  126. package/src/widgets/BottomDrawer/previewMobile.module.css +124 -0
  127. package/src/widgets/BottomDrawer/style.module.css +279 -0
  128. package/src/widgets/CaptivateBanner/captivateBanner.tsx +200 -0
  129. package/src/widgets/CaptivateBanner/config.ts +72 -0
  130. package/src/widgets/CaptivateBanner/index.tsx +204 -0
  131. package/src/widgets/CaptivateBanner/previewDesktop.module.css +51 -0
  132. package/src/widgets/CaptivateBanner/previewMobile.module.css +51 -0
  133. package/src/widgets/CaptivateBanner/style.module.css +77 -0
  134. package/src/widgets/CaptivateBanner/utils.ts +104 -0
  135. package/src/widgets/CentrallyAlignedPopup/config.ts +42 -0
  136. package/src/widgets/CentrallyAlignedPopup/index.tsx +109 -0
  137. package/src/widgets/CentrallyAlignedPopup/modal.tsx +269 -0
  138. package/src/widgets/CentrallyAlignedPopup/preview.module.css +153 -0
  139. package/src/widgets/CentrallyAlignedPopup/previewMobile.module.css +153 -0
  140. package/src/widgets/CentrallyAlignedPopup/style.module.css +283 -0
  141. package/src/widgets/DirectReward/components/couponDetails.tsx +265 -0
  142. package/src/widgets/DirectReward/components/userDetails.tsx +117 -0
  143. package/src/widgets/DirectReward/config.ts +186 -0
  144. package/src/widgets/DirectReward/directReward.tsx +350 -0
  145. package/src/widgets/DirectReward/index.tsx +579 -0
  146. package/src/widgets/DirectReward/previewStyles/thankYouPreviewDesktop.module.css +276 -0
  147. package/src/widgets/DirectReward/previewStyles/thankYouPreviewMobile.module.css +303 -0
  148. package/src/widgets/DirectReward/previewStyles/userDetailsPreviewDesktop.module.css +511 -0
  149. package/src/widgets/DirectReward/previewStyles/userDetailsPreviewMobile.module.css +462 -0
  150. package/src/widgets/DirectReward/style.module.css +836 -0
  151. package/src/widgets/ExitIntentHook.tsx +28 -0
  152. package/src/widgets/STW/api.ts +70 -0
  153. package/src/widgets/STW/components/svgFactory.tsx +44 -0
  154. package/src/widgets/STW/config.ts +193 -0
  155. package/src/widgets/STW/context.ts +7 -0
  156. package/src/widgets/STW/couponDetails.tsx +121 -0
  157. package/src/widgets/STW/index.tsx +733 -0
  158. package/src/widgets/STW/previewStyles/thankyouPreviewDesktop.module.css +215 -0
  159. package/src/widgets/STW/previewStyles/thankyouPreviewMobile.module.css +205 -0
  160. package/src/widgets/STW/previewStyles/userInputsPreviewDesktop.module.css +732 -0
  161. package/src/widgets/STW/previewStyles/userInputsPreviewMobile.module.css +661 -0
  162. package/src/widgets/STW/previewStyles/wheelPreviewDesktop.module.css +498 -0
  163. package/src/widgets/STW/previewStyles/wheelPreviewMobile.module.css +497 -0
  164. package/src/widgets/STW/stw1.tsx +119 -0
  165. package/src/widgets/STW/stw2Components/wheelDesign.tsx +183 -0
  166. package/src/widgets/STW/stw2Pages/couponDetails.tsx +72 -0
  167. package/src/widgets/STW/stw2Pages/stw2.tsx +212 -0
  168. package/src/widgets/STW/stw2Pages/style.module.css +1226 -0
  169. package/src/widgets/STW/stw2Pages/userDetails.tsx +86 -0
  170. package/src/widgets/STW/stw2Pages/wheel.tsx +117 -0
  171. package/src/widgets/STW/stw2PreviewStyles/thankyouPreviewDesktop.module.css +835 -0
  172. package/src/widgets/STW/stw2PreviewStyles/thankyouPreviewMobile.module.css +787 -0
  173. package/src/widgets/STW/stw2PreviewStyles/userInputsPreviewDesktop.module.css +867 -0
  174. package/src/widgets/STW/stw2PreviewStyles/userInputsPreviewMobile.module.css +798 -0
  175. package/src/widgets/STW/stw2PreviewStyles/wheelPreviewDesktop.module.css +572 -0
  176. package/src/widgets/STW/stw2PreviewStyles/wheelPreviewMobile.module.css +559 -0
  177. package/src/widgets/STW/style.module.css +901 -0
  178. package/src/widgets/STW/userDetails.tsx +150 -0
  179. package/src/widgets/STW/utility.ts +664 -0
  180. package/src/widgets/STW/wheel.tsx +304 -0
  181. package/src/widgets/ScratchCard/ScratchOff/scratchOff.tsx +157 -0
  182. package/src/widgets/ScratchCard/config.ts +152 -0
  183. package/src/widgets/ScratchCard/globalStyle.module.css +931 -0
  184. package/src/widgets/ScratchCard/index.tsx +546 -0
  185. package/src/widgets/ScratchCard/modal.tsx +225 -0
  186. package/src/widgets/ScratchCard/preview.module.css +250 -0
  187. package/src/widgets/ScratchCard/previewMobile.module.css +247 -0
  188. package/src/widgets/ScratchCard/previewStyles/userDetailsPreviewDesktop.module.css +537 -0
  189. package/src/widgets/ScratchCard/previewStyles/userDetailsPreviewMobile.module.css +463 -0
  190. package/src/widgets/ScratchCard/style.module.css +220 -0
  191. package/src/widgets/ShopifyForm/config.ts +168 -0
  192. package/src/widgets/ShopifyForm/index.tsx +214 -0
  193. package/src/widgets/ShopifyForm/previewDesktop.module.css +117 -0
  194. package/src/widgets/ShopifyForm/previewMobile.module.css +131 -0
  195. package/src/widgets/ShopifyForm/shopifyForm.tsx +445 -0
  196. package/src/widgets/ShopifyForm/style.module.css +161 -0
  197. package/src/widgets/SingleButtonRedirection/config.ts +47 -0
  198. package/src/widgets/SingleButtonRedirection/index.tsx +121 -0
  199. package/src/widgets/WebStories/config.ts +105 -0
  200. package/src/widgets/WebStories/index.css +3 -0
  201. package/src/widgets/WebStories/index.tsx +282 -0
  202. package/src/widgets/WebStories/style.module.css +26 -0
  203. package/src/widgets/index.tsx +3 -0
  204. package/src/widgets/utility.ts +31 -0
  205. package/tsconfig.json +12 -0
  206. package/webpack.config.js +239 -0
@@ -0,0 +1,342 @@
1
+ 'use strict';
2
+ /**
3
+ * Considerations
4
+ * if path is greater we can ignore it
5
+ * fallback path query params should not be considered
6
+ */
7
+ var __assign =
8
+ (this && this.__assign) ||
9
+ function () {
10
+ __assign =
11
+ Object.assign ||
12
+ function (t) {
13
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
14
+ s = arguments[i];
15
+ for (var p in s)
16
+ if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
17
+ }
18
+ return t;
19
+ };
20
+ return __assign.apply(this, arguments);
21
+ };
22
+ exports.__esModule = true;
23
+ exports.WidgetUtils = exports.FAB_POSITION = void 0;
24
+ var FAB_POSITION;
25
+ (function (FAB_POSITION) {
26
+ FAB_POSITION['BOTTOM_LEFT'] = 'BOTTOM_LEFT';
27
+ FAB_POSITION['BOTTOM_RIGHT'] = 'BOTTOM_RIGHT';
28
+ FAB_POSITION['CENTER_LEFT'] = 'CENTER_LEFT';
29
+ FAB_POSITION['CENTER_RIGHT'] = 'CENTER_RIGHT';
30
+ FAB_POSITION['POP_UP'] = 'POP_UP';
31
+ })((FAB_POSITION = exports.FAB_POSITION || (exports.FAB_POSITION = {})));
32
+ function isInIframe() {
33
+ try {
34
+ return window.self !== window.top;
35
+ } catch (e) {
36
+ return true;
37
+ }
38
+ }
39
+ var WidgetUtils = /** @class */ (function () {
40
+ function WidgetUtils() {}
41
+ WidgetUtils.prototype.isValidUrl = function (urlString) {
42
+ var urlPattern = new RegExp(
43
+ '^(https?:\\/\\/)?' +
44
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' +
45
+ '((\\d{1,3}\\.){3}\\d{1,3}))' +
46
+ '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
47
+ '(\\?[;&a-z\\d%_.~+=-]*)?' +
48
+ '(\\#[-a-z\\d_]*)?$',
49
+ 'i',
50
+ );
51
+ return !!urlPattern.test(urlString);
52
+ };
53
+ WidgetUtils.prototype.isHomePage = function (urlString) {
54
+ var urlPattern = urlString.match(/^\/(\?.*)?$/);
55
+ return !!urlPattern;
56
+ };
57
+ //entry point
58
+ WidgetUtils.prototype.showWidget = function (config, isAutomationTest) {
59
+ var _this = this;
60
+ var _a, _b;
61
+ try {
62
+ // if(!isAutomationTest && isInIframe()){
63
+ // console.log('return 1')
64
+ // return false;
65
+ // }
66
+ var updatedCustomUrls_1 = {};
67
+ Object.keys(config.customUrls).forEach(function (key) {
68
+ if (_this.isValidUrl(key)) {
69
+ var newUrl = new URL(key);
70
+ var correctKey = newUrl.href.replace(newUrl.origin, '');
71
+ updatedCustomUrls_1[correctKey] = config.customUrls[key];
72
+ } else {
73
+ updatedCustomUrls_1[key] = config.customUrls[key];
74
+ }
75
+ });
76
+ var updatedConfig_1 = __assign(__assign({}, config), {
77
+ customUrls: updatedCustomUrls_1,
78
+ });
79
+ //handling home page alone
80
+ var homePageWidgetsArray =
81
+ (_a = updatedConfig_1.customUrls['/']) !== null && _a !== void 0
82
+ ? _a
83
+ : [];
84
+ if (homePageWidgetsArray.length) {
85
+ var filtered = homePageWidgetsArray.filter(function (widget) {
86
+ return widget.widgetId == config.currentWidgetId;
87
+ });
88
+ if (filtered.length) {
89
+ if (updatedConfig_1.currentUrl == '/') {
90
+ return true;
91
+ }
92
+ var constructedUrl = new URL(
93
+ 'https://bik.ai' + updatedConfig_1.currentUrl,
94
+ );
95
+ if (constructedUrl.pathname == '/') {
96
+ return true;
97
+ }
98
+ }
99
+ }
100
+ //handling all pages
101
+ var allPagesWidgetsArray =
102
+ (_b = updatedConfig_1.customUrls['/*']) !== null && _b !== void 0
103
+ ? _b
104
+ : [];
105
+ console.log('allPagesWidgetsArray', allPagesWidgetsArray);
106
+ if (allPagesWidgetsArray.length) {
107
+ var filtered = allPagesWidgetsArray.filter(function (widget) {
108
+ return widget.widgetId == config.currentWidgetId;
109
+ });
110
+ console.log('filtered', filtered);
111
+ if (filtered.length) {
112
+ var currentWidgetPosition_1 = filtered[0].fabPosition;
113
+ var allWidgetedUrls = Object.keys(updatedConfig_1.customUrls);
114
+ var filteredWidgetedUrls = allWidgetedUrls.filter(function (url) {
115
+ return url !== '/*';
116
+ });
117
+ console.log('filteredWidgetedUrls', filteredWidgetedUrls);
118
+ var priorityUrls = [];
119
+ for (var i = 0; i < filteredWidgetedUrls.length; i++) {
120
+ if (
121
+ filteredWidgetedUrls[i] !== '/' &&
122
+ updatedConfig_1.currentUrl.startsWith(filteredWidgetedUrls[i])
123
+ ) {
124
+ priorityUrls.push(filteredWidgetedUrls[i]);
125
+ }
126
+ }
127
+ console.log('priorityUrls', priorityUrls);
128
+ if (!priorityUrls.length) {
129
+ return true;
130
+ }
131
+ for (var i = 0; i < priorityUrls.length; i++) {
132
+ var clashingWidgets = updatedConfig_1.customUrls[
133
+ priorityUrls[i]
134
+ ].filter(function (widget) {
135
+ return (
136
+ widget.widgetId !== updatedConfig_1.currentWidgetId &&
137
+ widget.fabPosition === currentWidgetPosition_1
138
+ );
139
+ });
140
+ console.log('clashingWidgets', clashingWidgets);
141
+ if (clashingWidgets.length) {
142
+ return false;
143
+ }
144
+ }
145
+ return true;
146
+ }
147
+ }
148
+ var ans = this.findExactMatch(updatedConfig_1);
149
+ if (ans && ans === config.currentWidgetId) {
150
+ return true;
151
+ }
152
+ var fuzzyAns = this.tryFuzzyMatch(updatedConfig_1);
153
+ console.log('fuzzyAns', fuzzyAns);
154
+ return fuzzyAns && fuzzyAns === config.currentWidgetId;
155
+ } catch (err) {
156
+ return false;
157
+ }
158
+ };
159
+ WidgetUtils.prototype.findExactMatch = function (config) {
160
+ try {
161
+ // try exact match
162
+ var ans_1;
163
+ if (config.customUrls[config.currentUrl]) {
164
+ var values = config.customUrls[config.currentUrl];
165
+ if (values.length) {
166
+ values.forEach(function (item) {
167
+ if (item.widgetId == config.currentWidgetId) {
168
+ ans_1 = config.currentWidgetId;
169
+ }
170
+ });
171
+ }
172
+ }
173
+ return ans_1;
174
+ } catch (err) {
175
+ return;
176
+ }
177
+ };
178
+ WidgetUtils.prototype.tryFuzzyMatch = function (config) {
179
+ var _this = this;
180
+ try {
181
+ var ans_2 = null;
182
+ var currentUrlRaw = config.currentUrl.replace(/\/\?/, '?');
183
+ var currentUrl_1 = this.separatePathAndQuery(
184
+ currentUrlRaw,
185
+ config.currentWidgetId,
186
+ );
187
+ if (!currentUrl_1) {
188
+ return;
189
+ }
190
+ // try max path match
191
+ var onlyUrls = Object.keys(config.customUrls);
192
+ var currentUrlPathLength_1 = currentUrl_1.path.split('/').length;
193
+ var possibleMatches_1 = [];
194
+ var possibleFallback_1 = {
195
+ path: '',
196
+ query: [],
197
+ count: 0,
198
+ };
199
+ onlyUrls.forEach(function (url) {
200
+ // if number of paths are greater than current url paths - ignore them
201
+ // only consider the path part here - remove/ignore the query params
202
+ if (_this.isHomePage(url)) return;
203
+ var values = config.customUrls[url];
204
+ values.forEach(function (item) {
205
+ var urlPath = _this.separatePathAndQuery(url, item.widgetId);
206
+ var urlPathLength =
207
+ urlPath === null || urlPath === void 0
208
+ ? void 0
209
+ : urlPath.path.split('/').length;
210
+ if (urlPathLength && urlPathLength > currentUrlPathLength_1) {
211
+ // Do nothing
212
+ } else if (urlPathLength == currentUrlPathLength_1) {
213
+ // check if they match
214
+ if (
215
+ (currentUrl_1 === null || currentUrl_1 === void 0
216
+ ? void 0
217
+ : currentUrl_1.path) ==
218
+ (urlPath === null || urlPath === void 0 ? void 0 : urlPath.path)
219
+ ) {
220
+ possibleMatches_1.push(urlPath);
221
+ }
222
+ } else {
223
+ // fallback
224
+ // consider only pure url i.e. only path and no query params
225
+ if (
226
+ !(urlPath === null || urlPath === void 0
227
+ ? void 0
228
+ : urlPath.query.length)
229
+ ) {
230
+ if (
231
+ (currentUrl_1 === null || currentUrl_1 === void 0
232
+ ? void 0
233
+ : currentUrl_1.path.includes(
234
+ urlPath === null || urlPath === void 0
235
+ ? void 0
236
+ : urlPath.path,
237
+ )) &&
238
+ currentUrl_1.count > possibleFallback_1.count
239
+ ) {
240
+ possibleFallback_1 = urlPath;
241
+ }
242
+ } else {
243
+ // Do nothing
244
+ }
245
+ }
246
+ });
247
+ });
248
+ if (possibleMatches_1.length) {
249
+ // if there are query params in currentUrl calculate max query match
250
+ if (currentUrl_1 && currentUrl_1.query.length) {
251
+ // find max query match
252
+ // even if one query param matches, consider that url
253
+ // else fallback to exact path match
254
+ var maxMatchPercentage_1 = 0;
255
+ var currentQueryHashMap_1 = new Map();
256
+ currentUrl_1.query.forEach(function (param) {
257
+ currentQueryHashMap_1.set(param, 1);
258
+ });
259
+ possibleMatches_1.forEach(function (possibleMatch) {
260
+ var matchCount = 0;
261
+ possibleMatch.query.forEach(function (query) {
262
+ if (currentQueryHashMap_1.has(query)) {
263
+ matchCount++;
264
+ }
265
+ });
266
+ var matchPercentage = currentUrl_1
267
+ ? (matchCount /
268
+ (possibleMatch.query.length + currentUrl_1.query.length)) *
269
+ 100
270
+ : 0;
271
+ if (maxMatchPercentage_1 < matchPercentage) {
272
+ maxMatchPercentage_1 = matchPercentage;
273
+ ans_2 = possibleMatch;
274
+ }
275
+ });
276
+ if (ans_2) {
277
+ // Do nothing
278
+ } else {
279
+ ans_2 = this.possibleMatchWithZeroQueryParam(possibleMatches_1);
280
+ if (ans_2 && ans_2.length) {
281
+ ans_2 = ans_2[0];
282
+ } else {
283
+ // if that is also empty, return best fallback
284
+ ans_2 = possibleFallback_1;
285
+ }
286
+ }
287
+ } else {
288
+ // if there are no query params in currentUrl, return the option with 0 query params
289
+ ans_2 = this.possibleMatchWithZeroQueryParam(possibleMatches_1);
290
+ if (ans_2 && ans_2.length) {
291
+ ans_2 = ans_2[0];
292
+ } else {
293
+ // if that is also empty, return best fallback
294
+ ans_2 = possibleFallback_1;
295
+ }
296
+ }
297
+ } else {
298
+ ans_2 = possibleFallback_1;
299
+ }
300
+ return (
301
+ (ans_2 === null || ans_2 === void 0 ? void 0 : ans_2.template) || null
302
+ );
303
+ } catch (err) {
304
+ return;
305
+ }
306
+ };
307
+ WidgetUtils.prototype.separatePathAndQuery = function (url, widgetId) {
308
+ try {
309
+ // any dummy base url will do
310
+ url = 'https://www.bik.ai' + url;
311
+ var newUrl = new URL(url);
312
+ var obj = {
313
+ path: '',
314
+ query: [],
315
+ count: 0,
316
+ template: widgetId,
317
+ };
318
+ obj.path = newUrl.pathname;
319
+ obj.count = newUrl.pathname.split('/').length;
320
+ if (newUrl.search) {
321
+ var params = newUrl.search.split('?');
322
+ obj.query = params[1].split('&');
323
+ }
324
+ return obj;
325
+ } catch (err) {
326
+ return;
327
+ }
328
+ };
329
+ WidgetUtils.prototype.possibleMatchWithZeroQueryParam = function (
330
+ possibleMatches,
331
+ ) {
332
+ try {
333
+ return possibleMatches.filter(function (possibleMatch) {
334
+ return !possibleMatch.query.length;
335
+ });
336
+ } catch (err) {
337
+ return;
338
+ }
339
+ };
340
+ return WidgetUtils;
341
+ })();
342
+ exports.WidgetUtils = WidgetUtils;
@@ -0,0 +1,313 @@
1
+ /**
2
+ * Considerations
3
+ * if path is greater we can ignore it
4
+ * fallback path query params should not be considered
5
+ */
6
+
7
+ export enum FAB_POSITION {
8
+ BOTTOM_LEFT = 'BOTTOM_LEFT',
9
+ BOTTOM_RIGHT = 'BOTTOM_RIGHT',
10
+ CENTER_LEFT = 'CENTER_LEFT',
11
+ CENTER_RIGHT = 'CENTER_RIGHT',
12
+ POP_UP = 'POP_UP',
13
+ }
14
+
15
+ export interface IPageConfigProcessed {
16
+ [key: string]: {
17
+ widgetId: string;
18
+ fabPosition: FAB_POSITION;
19
+ }[];
20
+ }
21
+
22
+ interface IShowWidget {
23
+ currentWidgetId: string;
24
+ customUrls: IPageConfigProcessed;
25
+ currentUrl: string;
26
+ }
27
+
28
+ interface IParsedUrl {
29
+ path: string;
30
+ query: string[];
31
+ count: number;
32
+ template?: string;
33
+ }
34
+
35
+ function isInIframe() {
36
+ try {
37
+ return window.self !== window.top;
38
+ } catch (e) {
39
+ return true;
40
+ }
41
+ }
42
+
43
+ export class WidgetUtils {
44
+ isValidUrl(urlString: string) {
45
+ const urlPattern = new RegExp(
46
+ '^(https?:\\/\\/)?' +
47
+ '((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' +
48
+ '((\\d{1,3}\\.){3}\\d{1,3}))' +
49
+ '(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' +
50
+ '(\\?[;&a-z\\d%_.~+=-]*)?' +
51
+ '(\\#[-a-z\\d_]*)?$',
52
+ 'i',
53
+ );
54
+ return !!urlPattern.test(urlString);
55
+ }
56
+
57
+ isHomePage(urlString: string) {
58
+ const urlPattern = urlString.match(/^\/(\?.*)?$/);
59
+ return !!urlPattern;
60
+ }
61
+
62
+ //entry point
63
+ showWidget(config: IShowWidget, isAutomationTest?: boolean) {
64
+ try {
65
+ if (!isAutomationTest && isInIframe()) {
66
+ return false;
67
+ }
68
+ let updatedCustomUrls: IPageConfigProcessed = {};
69
+ Object.keys(config.customUrls).forEach(key => {
70
+ if (this.isValidUrl(key)) {
71
+ const newUrl = new URL(key);
72
+ const correctKey = newUrl.href.replace(newUrl.origin, '');
73
+ updatedCustomUrls[correctKey] = config.customUrls[key];
74
+ } else {
75
+ updatedCustomUrls[key] = config.customUrls[key];
76
+ }
77
+ });
78
+ const updatedConfig: IShowWidget = {
79
+ ...config,
80
+ customUrls: updatedCustomUrls,
81
+ };
82
+ //handling home page alone
83
+ const homePageWidgetsArray = updatedConfig.customUrls['/'] ?? [];
84
+ if (homePageWidgetsArray.length) {
85
+ const filtered = homePageWidgetsArray.filter(
86
+ widget => widget.widgetId == config.currentWidgetId,
87
+ );
88
+ if (filtered.length) {
89
+ if (updatedConfig.currentUrl == '/') {
90
+ return true;
91
+ }
92
+ const constructedUrl = new URL(
93
+ 'https://bik.ai' + updatedConfig.currentUrl,
94
+ );
95
+ if (constructedUrl.pathname == '/') {
96
+ return true;
97
+ }
98
+ }
99
+ }
100
+
101
+ //handling all pages
102
+ const allPagesWidgetsArray = updatedConfig.customUrls['/*'] ?? [];
103
+ if (allPagesWidgetsArray.length) {
104
+ const filtered = allPagesWidgetsArray.filter(
105
+ widget => widget.widgetId == config.currentWidgetId,
106
+ );
107
+ if (filtered.length) {
108
+ const currentWidgetPosition = filtered[0].fabPosition;
109
+ const allWidgetedUrls = Object.keys(updatedConfig.customUrls);
110
+ const filteredWidgetedUrls = allWidgetedUrls.filter(
111
+ url => url !== '/*',
112
+ );
113
+ const priorityUrls = [];
114
+ for (let i = 0; i < filteredWidgetedUrls.length; i++) {
115
+ if (updatedConfig.currentUrl.startsWith(filteredWidgetedUrls[i])) {
116
+ priorityUrls.push(filteredWidgetedUrls[i]);
117
+ }
118
+ }
119
+ if (!priorityUrls.length) {
120
+ return true;
121
+ }
122
+ for (let i = 0; i < priorityUrls.length; i++) {
123
+ const clashingWidgets = updatedConfig.customUrls[
124
+ priorityUrls[i]
125
+ ].filter(widget => {
126
+ return (
127
+ widget.widgetId !== updatedConfig.currentWidgetId &&
128
+ widget.fabPosition === currentWidgetPosition
129
+ );
130
+ });
131
+ if (clashingWidgets.length) {
132
+ return false;
133
+ }
134
+ }
135
+ return true;
136
+ }
137
+ }
138
+ const ans = this.findExactMatch(updatedConfig);
139
+ if (ans && ans === config.currentWidgetId) {
140
+ return true;
141
+ }
142
+ const fuzzyAns = this.tryFuzzyMatch(updatedConfig);
143
+ return fuzzyAns && fuzzyAns === config.currentWidgetId;
144
+ } catch (err: any) {
145
+ return false;
146
+ }
147
+ }
148
+
149
+ findExactMatch(config: IShowWidget) {
150
+ try {
151
+ // try exact match
152
+ let ans;
153
+ if (config.customUrls[config.currentUrl]) {
154
+ const values = config.customUrls[config.currentUrl];
155
+ if (values.length) {
156
+ values.forEach(item => {
157
+ if (item.widgetId == config.currentWidgetId) {
158
+ ans = config.currentWidgetId;
159
+ }
160
+ });
161
+ }
162
+ }
163
+ return ans;
164
+ } catch (err: any) {
165
+ return;
166
+ }
167
+ }
168
+
169
+ tryFuzzyMatch(config: IShowWidget) {
170
+ try {
171
+ let ans = null;
172
+ const currentUrlRaw = config.currentUrl.replace(/\/\?/, '?');
173
+ const currentUrl = this.separatePathAndQuery(
174
+ currentUrlRaw,
175
+ config.currentWidgetId,
176
+ );
177
+ if (!currentUrl) {
178
+ return;
179
+ }
180
+ // try max path match
181
+ const onlyUrls = Object.keys(config.customUrls);
182
+ const currentUrlPathLength = currentUrl.path.split('/').length;
183
+ const possibleMatches: IParsedUrl[] = [];
184
+ let possibleFallback: IParsedUrl = {
185
+ path: '',
186
+ query: [],
187
+ count: 0,
188
+ };
189
+ onlyUrls.forEach(url => {
190
+ // if number of paths are greater than current url paths - ignore them
191
+ // only consider the path part here - remove/ignore the query params
192
+ if (this.isHomePage(url)) return;
193
+ const values = config.customUrls[url];
194
+ values.forEach(item => {
195
+ const urlPath = this.separatePathAndQuery(url, item.widgetId);
196
+ const urlPathLength = urlPath?.path.split('/').length;
197
+ if (urlPathLength && urlPathLength > currentUrlPathLength) {
198
+ // Do nothing
199
+ } else if (urlPathLength == currentUrlPathLength) {
200
+ // check if they match
201
+ if (currentUrl?.path == urlPath?.path) {
202
+ possibleMatches.push(urlPath);
203
+ }
204
+ } else {
205
+ // fallback
206
+ // consider only pure url i.e. only path and no query params
207
+ if (!urlPath?.query.length) {
208
+ if (
209
+ currentUrl?.path.includes(urlPath?.path as string) &&
210
+ currentUrl.count > possibleFallback.count
211
+ ) {
212
+ possibleFallback = urlPath as unknown as IParsedUrl;
213
+ }
214
+ } else {
215
+ // Do nothing
216
+ }
217
+ }
218
+ });
219
+ });
220
+
221
+ if (possibleMatches.length) {
222
+ // if there are query params in currentUrl calculate max query match
223
+ if (currentUrl && currentUrl.query.length) {
224
+ // find max query match
225
+ // even if one query param matches, consider that url
226
+ // else fallback to exact path match
227
+ let maxMatchPercentage = 0;
228
+
229
+ const currentQueryHashMap = new Map();
230
+ currentUrl.query.forEach(param => {
231
+ currentQueryHashMap.set(param, 1);
232
+ });
233
+ possibleMatches.forEach(possibleMatch => {
234
+ let matchCount = 0;
235
+ possibleMatch.query.forEach((query: string) => {
236
+ if (currentQueryHashMap.has(query)) {
237
+ matchCount++;
238
+ }
239
+ });
240
+ const matchPercentage = currentUrl
241
+ ? (matchCount /
242
+ (possibleMatch.query.length + currentUrl.query.length)) *
243
+ 100
244
+ : 0;
245
+ if (maxMatchPercentage < matchPercentage) {
246
+ maxMatchPercentage = matchPercentage;
247
+ ans = possibleMatch;
248
+ }
249
+ });
250
+
251
+ if (ans) {
252
+ // Do nothing
253
+ } else {
254
+ ans = this.possibleMatchWithZeroQueryParam(possibleMatches);
255
+ if (ans && ans.length) {
256
+ ans = ans[0];
257
+ } else {
258
+ // if that is also empty, return best fallback
259
+ ans = possibleFallback;
260
+ }
261
+ }
262
+ } else {
263
+ // if there are no query params in currentUrl, return the option with 0 query params
264
+ ans = this.possibleMatchWithZeroQueryParam(possibleMatches);
265
+ if (ans && ans.length) {
266
+ ans = ans[0];
267
+ } else {
268
+ // if that is also empty, return best fallback
269
+ ans = possibleFallback;
270
+ }
271
+ }
272
+ } else {
273
+ ans = possibleFallback;
274
+ }
275
+ return ans?.template || null;
276
+ } catch (err: any) {
277
+ return;
278
+ }
279
+ }
280
+
281
+ separatePathAndQuery(url: string, widgetId: string) {
282
+ try {
283
+ // any dummy base url will do
284
+ url = 'https://www.bik.ai' + url;
285
+ const newUrl = new URL(url);
286
+ const obj: IParsedUrl = {
287
+ path: '',
288
+ query: [],
289
+ count: 0,
290
+ template: widgetId,
291
+ };
292
+ obj.path = newUrl.pathname;
293
+ obj.count = newUrl.pathname.split('/').length;
294
+ if (newUrl.search) {
295
+ const params = newUrl.search.split('?');
296
+ obj.query = params[1].split('&');
297
+ }
298
+ return obj;
299
+ } catch (err: any) {
300
+ return;
301
+ }
302
+ }
303
+
304
+ possibleMatchWithZeroQueryParam(possibleMatches: IParsedUrl[]) {
305
+ try {
306
+ return possibleMatches.filter(
307
+ possibleMatch => !possibleMatch.query.length,
308
+ );
309
+ } catch (err: any) {
310
+ return;
311
+ }
312
+ }
313
+ }
@@ -0,0 +1,41 @@
1
+ import { IBottomDrawer } from './index';
2
+ const config: IBottomDrawer = {
3
+ preview: false,
4
+ environment: 'staging',
5
+ visibility: {
6
+ visiblePages: ['/', '/products'],
7
+ },
8
+ widgetCustomisation: {
9
+ iconColor: '#000000',
10
+ fabBackgroundColor: '#FBDC7E',
11
+ widgetName: 'Bottom Drawer tmyv',
12
+ redirectWidgetBackgroundColor: '',
13
+ redirectWidgetTitleText: 'Connect with us!',
14
+ redirectWidgetBannerImage:
15
+ 'https://png.pngtree.com/thumb_back/fh260/back_pic/02/50/63/71577e1cf59d802.jpg',
16
+ livechatEnabled: false,
17
+ whatsapp: '916364856308',
18
+ whatsappMessage: 'afas',
19
+ emailSubject: '',
20
+ emailBody: '',
21
+ fabPositioner: {
22
+ bottom: '30px',
23
+ right: '30px',
24
+ },
25
+ fabIconLink:
26
+ 'https://storage.googleapis.com/bik-widget-mfe/bap%2Ffab-assets%2Ficons%2Fbik%2Fredirect.svg',
27
+ fabPosition: 'BOTTOM_RIGHT',
28
+ fabMobileSize: 50,
29
+ fabWebSize: 50,
30
+ multiLingualConfigurations: {
31
+ ENGLISH: {
32
+ redirectWidgetTitleText: 'Connect English',
33
+ },
34
+ FRENCH: {
35
+ redirectWidgetTitleText: 'Connect French',
36
+ },
37
+ },
38
+ },
39
+ };
40
+
41
+ export default config;