@bikdotai/bik-widgets 1.0.0 → 1.0.2

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 (207) hide show
  1. package/dist-package/index.css +95 -0
  2. package/dist-package/index.js +2 -0
  3. package/package.json +17 -4
  4. package/.eslintrc +0 -22
  5. package/.eslintrc.js +0 -19
  6. package/.github/workflows/main.yml +0 -293
  7. package/.prettierignore +0 -13
  8. package/.prettierrc +0 -10
  9. package/cypress/apiHelper/endpoints.ts +0 -21
  10. package/cypress/apiHelper/executor.ts +0 -42
  11. package/cypress/e2e/bottomDrawer.cy.ts +0 -49
  12. package/cypress/e2e/directReward.cy.ts +0 -67
  13. package/cypress/e2e/scratchTheCard.cy.ts +0 -68
  14. package/cypress/e2e/stw.cy.ts +0 -82
  15. package/cypress/e2e/waRedirection.cy.ts +0 -46
  16. package/cypress/fixtures/payloads.ts +0 -330
  17. package/cypress/support/commands.ts +0 -37
  18. package/cypress/support/e2e.ts +0 -20
  19. package/cypress.staging.config.ts +0 -23
  20. package/jsconfig.json +0 -6
  21. package/localtest.sh +0 -10
  22. package/log-server.js +0 -86
  23. package/postcss.config.js +0 -8
  24. package/src/Globals.d.ts +0 -2
  25. package/src/assets/lottie/santa.json +0 -11722
  26. package/src/assets/svg/CalendarClockIcon.tsx +0 -30
  27. package/src/assets/svg/CalendarIcon.tsx +0 -24
  28. package/src/assets/svg/CheckIcon.tsx +0 -17
  29. package/src/assets/svg/ChevronIcon.tsx +0 -21
  30. package/src/assets/svg/Close.tsx +0 -39
  31. package/src/assets/svg/Confetti.tsx +0 -140
  32. package/src/assets/svg/Copy.tsx +0 -26
  33. package/src/assets/svg/DropdownCheckIcon.tsx +0 -35
  34. package/src/assets/svg/ErrorIcon.tsx +0 -27
  35. package/src/assets/svg/RadioIcon.tsx +0 -25
  36. package/src/assets/svg/UncheckedCheckboxIcon.tsx +0 -28
  37. package/src/assets/svg/UncheckedRadioIcon.tsx +0 -26
  38. package/src/assets/svg/info.tsx +0 -30
  39. package/src/assets/svg/qrcode.svg +0 -14
  40. package/src/bootstrap.tsx +0 -8
  41. package/src/components/CtaCard/index.tsx +0 -37
  42. package/src/components/CtaCard/preview.module.css +0 -32
  43. package/src/components/CtaCard/style.module.css +0 -32
  44. package/src/components/EmailInput/emailInputBox.tsx +0 -95
  45. package/src/components/Fab/index.tsx +0 -224
  46. package/src/components/Fab/preview.module.css +0 -28
  47. package/src/components/Fab/style.module.css +0 -37
  48. package/src/components/Icons/Call.tsx +0 -26
  49. package/src/components/Icons/Cross.tsx +0 -24
  50. package/src/components/Icons/Gmail.tsx +0 -61
  51. package/src/components/Icons/Instagram.tsx +0 -60
  52. package/src/components/Icons/LiveChat.tsx +0 -43
  53. package/src/components/Icons/Messenger.tsx +0 -57
  54. package/src/components/Icons/Send.tsx +0 -22
  55. package/src/components/Icons/Whatsapp.tsx +0 -24
  56. package/src/components/Shimmer/index.tsx +0 -12
  57. package/src/components/Shimmer/style.module.css +0 -37
  58. package/src/components/SmsInput/smsInputBox.tsx +0 -135
  59. package/src/components/UserDetailsV2/userDetailsV2.desktop.module.css +0 -52
  60. package/src/components/UserDetailsV2/userDetailsV2.mobile.module.css +0 -52
  61. package/src/components/UserDetailsV2/userDetailsV2.module.css +0 -81
  62. package/src/components/UserDetailsV2/userDetailsV2.tsx +0 -527
  63. package/src/components/WhatsappInput/Spinner.tsx +0 -26
  64. package/src/components/WhatsappInput/whatsappInput.module.css +0 -106
  65. package/src/components/WhatsappInput/whatsappInputBox.tsx +0 -155
  66. package/src/components/WhatsappInput/whatsappInputPreviewDesktop.module.css +0 -71
  67. package/src/components/WhatsappInput/whatsappInputPreviewMobile.module.css +0 -65
  68. package/src/components/checkbox/checkbox.module.css +0 -19
  69. package/src/components/checkbox/checkbox.tsx +0 -88
  70. package/src/components/countryCodePicker/countriesDropdown.module.css +0 -77
  71. package/src/components/countryCodePicker/countriesDropdown.tsx +0 -81
  72. package/src/components/couponDetails/coupon.module.css +0 -208
  73. package/src/components/couponDetails/coupon.tsx +0 -210
  74. package/src/components/couponDetails/couponPreviewDesktop.module.css +0 -158
  75. package/src/components/couponDetails/couponPreviewMobile.module.css +0 -164
  76. package/src/components/index.ts +0 -3
  77. package/src/components/inputComponents/Checkbox.module.css +0 -197
  78. package/src/components/inputComponents/Checkbox.tsx +0 -85
  79. package/src/components/inputComponents/DatePicker.module.css +0 -565
  80. package/src/components/inputComponents/DatePicker.tsx +0 -278
  81. package/src/components/inputComponents/Dropdown.module.css +0 -796
  82. package/src/components/inputComponents/Dropdown.tsx +0 -630
  83. package/src/components/inputComponents/InputBox.module.css +0 -401
  84. package/src/components/inputComponents/InputBox.tsx +0 -209
  85. package/src/components/selectedCountry/selectedCountry.module.css +0 -76
  86. package/src/components/selectedCountry/selectedCountry.tsx +0 -76
  87. package/src/components/selectedCountry/selectedCountryPreviewDesktop.module.css +0 -56
  88. package/src/components/selectedCountry/selectedCountryPreviewMobile.module.css +0 -57
  89. package/src/components/userDetailsForm/RenderCustomFields.tsx +0 -333
  90. package/src/components/userDetailsForm/userDetailsForm.tsx +0 -675
  91. package/src/hooks/index.ts +0 -4
  92. package/src/hooks/useExitIntent.ts +0 -452
  93. package/src/hooks/useIsMobile.tsx +0 -21
  94. package/src/hooks/useMessageEvent.ts +0 -8
  95. package/src/hooks/useTriggeredIntentDetails.ts +0 -43
  96. package/src/hooks/useUrlListerner.ts +0 -30
  97. package/src/hooks/useWebSocketLogger.ts +0 -59
  98. package/src/hooks/useWindowEvent.ts +0 -8
  99. package/src/icons/copyIcon.tsx +0 -26
  100. package/src/icons/crossIconDesktop.tsx +0 -20
  101. package/src/icons/crossIconMobile.tsx +0 -20
  102. package/src/index.html +0 -30
  103. package/src/index.ts +0 -32
  104. package/src/index.tsx +0 -1
  105. package/src/repo/widgetRepo.ts +0 -21
  106. package/src/types/customFields.ts +0 -73
  107. package/src/utilities/cookie.ts +0 -70
  108. package/src/utilities/customFieldTypeMapping.ts +0 -67
  109. package/src/utilities/customFieldValidation.ts +0 -201
  110. package/src/utilities/encryption.ts +0 -21
  111. package/src/utilities/exitIntentUtils.ts +0 -31
  112. package/src/utilities/global.css +0 -11
  113. package/src/utilities/languageUtilities.ts +0 -235
  114. package/src/utilities/localRunner.js +0 -26
  115. package/src/utilities/localRunner.ts +0 -27
  116. package/src/utilities/localStorage.ts +0 -40
  117. package/src/utilities/script.tsx +0 -15
  118. package/src/utilities/stringUtils.ts +0 -5
  119. package/src/utilities/styleUtils.ts +0 -134
  120. package/src/utilities/variables.ts +0 -11
  121. package/src/utilities/widgetUtils.js +0 -342
  122. package/src/utilities/widgetUtils.ts +0 -313
  123. package/src/widgets/BottomDrawer/config.ts +0 -41
  124. package/src/widgets/BottomDrawer/index.tsx +0 -116
  125. package/src/widgets/BottomDrawer/modal.tsx +0 -286
  126. package/src/widgets/BottomDrawer/preview.module.css +0 -122
  127. package/src/widgets/BottomDrawer/previewMobile.module.css +0 -124
  128. package/src/widgets/BottomDrawer/style.module.css +0 -279
  129. package/src/widgets/CaptivateBanner/captivateBanner.tsx +0 -200
  130. package/src/widgets/CaptivateBanner/config.ts +0 -72
  131. package/src/widgets/CaptivateBanner/index.tsx +0 -204
  132. package/src/widgets/CaptivateBanner/previewDesktop.module.css +0 -51
  133. package/src/widgets/CaptivateBanner/previewMobile.module.css +0 -51
  134. package/src/widgets/CaptivateBanner/style.module.css +0 -77
  135. package/src/widgets/CaptivateBanner/utils.ts +0 -104
  136. package/src/widgets/CentrallyAlignedPopup/config.ts +0 -42
  137. package/src/widgets/CentrallyAlignedPopup/index.tsx +0 -109
  138. package/src/widgets/CentrallyAlignedPopup/modal.tsx +0 -269
  139. package/src/widgets/CentrallyAlignedPopup/preview.module.css +0 -153
  140. package/src/widgets/CentrallyAlignedPopup/previewMobile.module.css +0 -153
  141. package/src/widgets/CentrallyAlignedPopup/style.module.css +0 -283
  142. package/src/widgets/DirectReward/components/couponDetails.tsx +0 -265
  143. package/src/widgets/DirectReward/components/userDetails.tsx +0 -117
  144. package/src/widgets/DirectReward/config.ts +0 -186
  145. package/src/widgets/DirectReward/directReward.tsx +0 -350
  146. package/src/widgets/DirectReward/index.tsx +0 -579
  147. package/src/widgets/DirectReward/previewStyles/thankYouPreviewDesktop.module.css +0 -276
  148. package/src/widgets/DirectReward/previewStyles/thankYouPreviewMobile.module.css +0 -303
  149. package/src/widgets/DirectReward/previewStyles/userDetailsPreviewDesktop.module.css +0 -511
  150. package/src/widgets/DirectReward/previewStyles/userDetailsPreviewMobile.module.css +0 -462
  151. package/src/widgets/DirectReward/style.module.css +0 -836
  152. package/src/widgets/ExitIntentHook.tsx +0 -28
  153. package/src/widgets/STW/api.ts +0 -70
  154. package/src/widgets/STW/components/svgFactory.tsx +0 -44
  155. package/src/widgets/STW/config.ts +0 -193
  156. package/src/widgets/STW/context.ts +0 -7
  157. package/src/widgets/STW/couponDetails.tsx +0 -121
  158. package/src/widgets/STW/index.tsx +0 -733
  159. package/src/widgets/STW/previewStyles/thankyouPreviewDesktop.module.css +0 -215
  160. package/src/widgets/STW/previewStyles/thankyouPreviewMobile.module.css +0 -205
  161. package/src/widgets/STW/previewStyles/userInputsPreviewDesktop.module.css +0 -732
  162. package/src/widgets/STW/previewStyles/userInputsPreviewMobile.module.css +0 -661
  163. package/src/widgets/STW/previewStyles/wheelPreviewDesktop.module.css +0 -498
  164. package/src/widgets/STW/previewStyles/wheelPreviewMobile.module.css +0 -497
  165. package/src/widgets/STW/stw1.tsx +0 -119
  166. package/src/widgets/STW/stw2Components/wheelDesign.tsx +0 -183
  167. package/src/widgets/STW/stw2Pages/couponDetails.tsx +0 -72
  168. package/src/widgets/STW/stw2Pages/stw2.tsx +0 -212
  169. package/src/widgets/STW/stw2Pages/style.module.css +0 -1226
  170. package/src/widgets/STW/stw2Pages/userDetails.tsx +0 -86
  171. package/src/widgets/STW/stw2Pages/wheel.tsx +0 -117
  172. package/src/widgets/STW/stw2PreviewStyles/thankyouPreviewDesktop.module.css +0 -835
  173. package/src/widgets/STW/stw2PreviewStyles/thankyouPreviewMobile.module.css +0 -787
  174. package/src/widgets/STW/stw2PreviewStyles/userInputsPreviewDesktop.module.css +0 -867
  175. package/src/widgets/STW/stw2PreviewStyles/userInputsPreviewMobile.module.css +0 -798
  176. package/src/widgets/STW/stw2PreviewStyles/wheelPreviewDesktop.module.css +0 -572
  177. package/src/widgets/STW/stw2PreviewStyles/wheelPreviewMobile.module.css +0 -559
  178. package/src/widgets/STW/style.module.css +0 -901
  179. package/src/widgets/STW/userDetails.tsx +0 -150
  180. package/src/widgets/STW/utility.ts +0 -664
  181. package/src/widgets/STW/wheel.tsx +0 -304
  182. package/src/widgets/ScratchCard/ScratchOff/scratchOff.tsx +0 -157
  183. package/src/widgets/ScratchCard/config.ts +0 -152
  184. package/src/widgets/ScratchCard/globalStyle.module.css +0 -931
  185. package/src/widgets/ScratchCard/index.tsx +0 -546
  186. package/src/widgets/ScratchCard/modal.tsx +0 -225
  187. package/src/widgets/ScratchCard/preview.module.css +0 -250
  188. package/src/widgets/ScratchCard/previewMobile.module.css +0 -247
  189. package/src/widgets/ScratchCard/previewStyles/userDetailsPreviewDesktop.module.css +0 -537
  190. package/src/widgets/ScratchCard/previewStyles/userDetailsPreviewMobile.module.css +0 -463
  191. package/src/widgets/ScratchCard/style.module.css +0 -220
  192. package/src/widgets/ShopifyForm/config.ts +0 -168
  193. package/src/widgets/ShopifyForm/index.tsx +0 -214
  194. package/src/widgets/ShopifyForm/previewDesktop.module.css +0 -117
  195. package/src/widgets/ShopifyForm/previewMobile.module.css +0 -131
  196. package/src/widgets/ShopifyForm/shopifyForm.tsx +0 -445
  197. package/src/widgets/ShopifyForm/style.module.css +0 -161
  198. package/src/widgets/SingleButtonRedirection/config.ts +0 -47
  199. package/src/widgets/SingleButtonRedirection/index.tsx +0 -121
  200. package/src/widgets/WebStories/config.ts +0 -105
  201. package/src/widgets/WebStories/index.css +0 -3
  202. package/src/widgets/WebStories/index.tsx +0 -282
  203. package/src/widgets/WebStories/style.module.css +0 -26
  204. package/src/widgets/index.tsx +0 -3
  205. package/src/widgets/utility.ts +0 -31
  206. package/tsconfig.json +0 -12
  207. package/webpack.config.js +0 -239
@@ -1,342 +0,0 @@
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;
@@ -1,313 +0,0 @@
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
- }
@@ -1,41 +0,0 @@
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;