surveysparrow-ionic-plugin 2.0.3 → 2.1.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 (125) hide show
  1. package/dist/angular-ui/fesm2022/angular-ui.mjs +1203 -998
  2. package/dist/angular-ui/fesm2022/angular-ui.mjs.map +1 -1
  3. package/dist/angular-ui/index.d.ts +119 -5
  4. package/dist/docs.json +13 -5
  5. package/dist/esm/angular-ui/lib/public-api.js.map +1 -1
  6. package/dist/esm/angular-ui/lib/spotcheck.component.d.ts +30 -1
  7. package/dist/esm/angular-ui/lib/spotcheck.component.js +194 -4
  8. package/dist/esm/angular-ui/lib/spotcheck.component.js.map +1 -1
  9. package/dist/esm/angular-ui/lib/spotchecks/components/builder.component.d.ts +57 -0
  10. package/dist/esm/angular-ui/lib/spotchecks/components/builder.component.js +284 -0
  11. package/dist/esm/angular-ui/lib/spotchecks/components/builder.component.js.map +1 -0
  12. package/dist/esm/angular-ui/lib/spotchecks/helpers/binding.d.ts +25 -0
  13. package/dist/esm/angular-ui/lib/spotchecks/helpers/binding.js +107 -0
  14. package/dist/esm/angular-ui/lib/spotchecks/helpers/binding.js.map +1 -0
  15. package/dist/esm/angular-ui/lib/spotchecks/helpers/device.d.ts +11 -0
  16. package/dist/esm/angular-ui/lib/spotchecks/helpers/device.js +48 -0
  17. package/dist/esm/angular-ui/lib/spotchecks/helpers/device.js.map +1 -0
  18. package/dist/esm/angular-ui/lib/spotchecks/helpers/executables.d.ts +4 -0
  19. package/dist/esm/angular-ui/lib/spotchecks/helpers/executables.js +113 -0
  20. package/dist/esm/angular-ui/lib/spotchecks/helpers/executables.js.map +1 -0
  21. package/dist/esm/angular-ui/lib/spotchecks/helpers/listener.d.ts +9 -0
  22. package/dist/esm/angular-ui/lib/spotchecks/helpers/listener.js +55 -0
  23. package/dist/esm/angular-ui/lib/spotchecks/helpers/listener.js.map +1 -0
  24. package/dist/esm/angular-ui/lib/spotchecks/helpers/render.d.ts +5 -0
  25. package/dist/esm/angular-ui/lib/spotchecks/helpers/render.js +43 -0
  26. package/dist/esm/angular-ui/lib/spotchecks/helpers/render.js.map +1 -0
  27. package/dist/esm/angular-ui/lib/spotchecks/helpers/sentry.d.ts +7 -0
  28. package/dist/esm/angular-ui/lib/spotchecks/helpers/sentry.js +115 -0
  29. package/dist/esm/angular-ui/lib/spotchecks/helpers/sentry.js.map +1 -0
  30. package/dist/esm/angular-ui/lib/spotchecks/helpers/storage.d.ts +3 -0
  31. package/dist/esm/angular-ui/lib/spotchecks/helpers/storage.js +40 -0
  32. package/dist/esm/angular-ui/lib/spotchecks/helpers/storage.js.map +1 -0
  33. package/dist/esm/angular-ui/lib/spotchecks/helpers/survey-page.d.ts +22 -0
  34. package/dist/esm/angular-ui/lib/spotchecks/helpers/survey-page.js +128 -0
  35. package/dist/esm/angular-ui/lib/spotchecks/helpers/survey-page.js.map +1 -0
  36. package/dist/esm/angular-ui/lib/spotchecks/helpers/version.d.ts +2 -0
  37. package/dist/esm/angular-ui/lib/spotchecks/helpers/version.js +4 -0
  38. package/dist/esm/angular-ui/lib/spotchecks/helpers/version.js.map +1 -0
  39. package/dist/esm/angular-ui/lib/spotchecks/index.d.ts +4 -3
  40. package/dist/esm/angular-ui/lib/spotchecks/index.js +2 -2
  41. package/dist/esm/angular-ui/lib/spotchecks/index.js.map +1 -1
  42. package/dist/esm/angular-ui/lib/spotchecks/spotcheck.d.ts +8 -0
  43. package/dist/esm/angular-ui/lib/spotchecks/spotcheck.js +147 -0
  44. package/dist/esm/angular-ui/lib/spotchecks/spotcheck.js.map +1 -0
  45. package/dist/esm/angular-ui/lib/spotchecks/state/store.d.ts +14 -0
  46. package/dist/esm/angular-ui/lib/spotchecks/state/store.js +109 -0
  47. package/dist/esm/angular-ui/lib/spotchecks/state/store.js.map +1 -0
  48. package/dist/esm/angular-ui/lib/spotchecks/types.d.ts +22 -58
  49. package/dist/esm/angular-ui/lib/spotchecks/types.js.map +1 -1
  50. package/dist/plugin.cjs.js +1211 -51762
  51. package/dist/plugin.cjs.js.map +1 -1
  52. package/dist/plugin.js +1209 -51761
  53. package/dist/plugin.js.map +1 -1
  54. package/package.json +4 -8
  55. package/src/angular-ui/lib/public-api.ts +1 -1
  56. package/src/angular-ui/lib/spotcheck.component.ts +202 -5
  57. package/src/angular-ui/lib/spotchecks/components/builder.component.ts +254 -0
  58. package/src/angular-ui/lib/spotchecks/helpers/binding.ts +126 -0
  59. package/src/angular-ui/lib/spotchecks/helpers/device.ts +51 -0
  60. package/src/angular-ui/lib/spotchecks/helpers/executables.ts +124 -0
  61. package/src/angular-ui/lib/spotchecks/helpers/listener.ts +61 -0
  62. package/src/angular-ui/lib/spotchecks/helpers/render.ts +44 -0
  63. package/src/angular-ui/lib/spotchecks/helpers/sentry.ts +127 -0
  64. package/src/angular-ui/lib/spotchecks/helpers/storage.ts +37 -0
  65. package/src/angular-ui/lib/spotchecks/helpers/survey-page.ts +120 -0
  66. package/src/angular-ui/lib/spotchecks/helpers/version.ts +3 -0
  67. package/src/angular-ui/lib/spotchecks/index.ts +11 -3
  68. package/src/angular-ui/lib/spotchecks/spotcheck.ts +150 -0
  69. package/src/angular-ui/lib/spotchecks/state/store.ts +126 -0
  70. package/src/angular-ui/lib/spotchecks/types.ts +26 -59
  71. package/src/angular-ui/ng-package.json +9 -12
  72. package/src/angular-ui/package.json +9 -8
  73. package/dist/angular-ui/esm2022/angular-ui.mjs +0 -5
  74. package/dist/angular-ui/esm2022/public-api.mjs +0 -3
  75. package/dist/angular-ui/esm2022/spotcheck.component.mjs +0 -17
  76. package/dist/angular-ui/esm2022/spotchecks/SpotCheck.mjs +0 -51
  77. package/dist/angular-ui/esm2022/spotchecks/SpotCheckComponent.mjs +0 -410
  78. package/dist/angular-ui/esm2022/spotchecks/SpotCheckEventListener.mjs +0 -26
  79. package/dist/angular-ui/esm2022/spotchecks/SpotcheckStateService.mjs +0 -67
  80. package/dist/angular-ui/esm2022/spotchecks/api.mjs +0 -230
  81. package/dist/angular-ui/esm2022/spotchecks/helpers.mjs +0 -338
  82. package/dist/angular-ui/esm2022/spotchecks/index.mjs +0 -3
  83. package/dist/angular-ui/esm2022/spotchecks/storage.mjs +0 -7
  84. package/dist/angular-ui/esm2022/spotchecks/types.mjs +0 -2
  85. package/dist/angular-ui/public-api.d.ts +0 -2
  86. package/dist/angular-ui/spotcheck.component.d.ts +0 -5
  87. package/dist/angular-ui/spotchecks/SpotCheck.d.ts +0 -4
  88. package/dist/angular-ui/spotchecks/SpotCheckComponent.d.ts +0 -65
  89. package/dist/angular-ui/spotchecks/SpotCheckEventListener.d.ts +0 -16
  90. package/dist/angular-ui/spotchecks/SpotcheckStateService.d.ts +0 -12
  91. package/dist/angular-ui/spotchecks/api.d.ts +0 -15
  92. package/dist/angular-ui/spotchecks/helpers.d.ts +0 -30
  93. package/dist/angular-ui/spotchecks/index.d.ts +0 -3
  94. package/dist/angular-ui/spotchecks/storage.d.ts +0 -2
  95. package/dist/angular-ui/spotchecks/types.d.ts +0 -80
  96. package/dist/esm/angular-ui/lib/spotchecks/SpotCheck.d.ts +0 -4
  97. package/dist/esm/angular-ui/lib/spotchecks/SpotCheck.js +0 -51
  98. package/dist/esm/angular-ui/lib/spotchecks/SpotCheck.js.map +0 -1
  99. package/dist/esm/angular-ui/lib/spotchecks/SpotCheckComponent.d.ts +0 -56
  100. package/dist/esm/angular-ui/lib/spotchecks/SpotCheckComponent.js +0 -397
  101. package/dist/esm/angular-ui/lib/spotchecks/SpotCheckComponent.js.map +0 -1
  102. package/dist/esm/angular-ui/lib/spotchecks/SpotCheckEventListener.d.ts +0 -16
  103. package/dist/esm/angular-ui/lib/spotchecks/SpotCheckEventListener.js +0 -28
  104. package/dist/esm/angular-ui/lib/spotchecks/SpotCheckEventListener.js.map +0 -1
  105. package/dist/esm/angular-ui/lib/spotchecks/SpotcheckStateService.d.ts +0 -9
  106. package/dist/esm/angular-ui/lib/spotchecks/SpotcheckStateService.js +0 -72
  107. package/dist/esm/angular-ui/lib/spotchecks/SpotcheckStateService.js.map +0 -1
  108. package/dist/esm/angular-ui/lib/spotchecks/api.d.ts +0 -15
  109. package/dist/esm/angular-ui/lib/spotchecks/api.js +0 -232
  110. package/dist/esm/angular-ui/lib/spotchecks/api.js.map +0 -1
  111. package/dist/esm/angular-ui/lib/spotchecks/helpers.d.ts +0 -30
  112. package/dist/esm/angular-ui/lib/spotchecks/helpers.js +0 -304
  113. package/dist/esm/angular-ui/lib/spotchecks/helpers.js.map +0 -1
  114. package/dist/esm/angular-ui/lib/spotchecks/storage.d.ts +0 -2
  115. package/dist/esm/angular-ui/lib/spotchecks/storage.js +0 -7
  116. package/dist/esm/angular-ui/lib/spotchecks/storage.js.map +0 -1
  117. package/src/angular-ui/lib/spotchecks/SpotCheck.ts +0 -54
  118. package/src/angular-ui/lib/spotchecks/SpotCheckComponent.css +0 -7
  119. package/src/angular-ui/lib/spotchecks/SpotCheckComponent.html +0 -27
  120. package/src/angular-ui/lib/spotchecks/SpotCheckComponent.ts +0 -389
  121. package/src/angular-ui/lib/spotchecks/SpotCheckEventListener.ts +0 -50
  122. package/src/angular-ui/lib/spotchecks/SpotcheckStateService.ts +0 -66
  123. package/src/angular-ui/lib/spotchecks/api.ts +0 -286
  124. package/src/angular-ui/lib/spotchecks/helpers.ts +0 -414
  125. package/src/angular-ui/lib/spotchecks/storage.ts +0 -7
@@ -1,286 +0,0 @@
1
- import { generateTraceId, getOS, setAppearance } from './helpers';
2
- import { getStoredUUID, setUUID } from './storage';
3
- import { TrackScreenProps, UserDetails, Variables, CustomProperties, TrackEventProps } from './types';
4
- import { getSpotcheckStateService } from './helpers';
5
- import axios from 'axios';
6
-
7
- export const sendTrackScreenRequest = async ({
8
- screen,
9
- options,
10
- }: TrackScreenProps) => {
11
- try {
12
- const spotcheckStateService = getSpotcheckStateService();
13
- const oldState = spotcheckStateService.getState();
14
- let variables = { ...oldState.variables } as Variables;
15
- let customProperties = { ...oldState.customProperties } as CustomProperties;
16
- let userDetails = { ...oldState.userDetails } as UserDetails;
17
-
18
- if (options && options.variables && Object.keys(options.variables).length > 0) {
19
- variables = { ...variables, ...options.variables };
20
- }
21
- if (options && options.customProperties && Object.keys(options.customProperties).length > 0) {
22
- customProperties = { ...customProperties, ...options.customProperties };
23
- }
24
- if (options && options.userDetails && Object.keys(options.userDetails).length > 0) {
25
- userDetails = { ...userDetails, ...options.userDetails };
26
- }
27
-
28
- let traceId = oldState.traceId;
29
- if (!traceId) {
30
- traceId = generateTraceId();
31
- }
32
-
33
- if (!userDetails.uuid && !userDetails.email && !userDetails.mobile) {
34
- const uuid = getStoredUUID();
35
- if (uuid) {
36
- userDetails.uuid = uuid;
37
- }
38
- }
39
-
40
- spotcheckStateService.setState({
41
- traceId,
42
- screenwiseUserDetails: {
43
- [screen]: userDetails
44
- },
45
- });
46
-
47
- const state = spotcheckStateService.getState();
48
- let { isSpotPassed, isChecksPassed } = state;
49
- const payload = {
50
- screenName: screen,
51
- variables: variables,
52
- userDetails: userDetails,
53
- visitor: {
54
- deviceType: 'MOBILE',
55
- operatingSystem: await getOS(),
56
- screenResolution: {
57
- height: window.innerHeight,
58
- width: window.innerWidth,
59
- },
60
- currentDate: new Date().toISOString(),
61
- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
62
- },
63
- traceId: state.traceId,
64
- customProperties: customProperties,
65
- };
66
-
67
- const url = `https://${state.domainName}/api/internal/spotcheck/widget/${state.targetToken}/properties?isSpotCheck=true&sdk=IONIC`;
68
- const response = await axios.post<any>(url, payload, {
69
- headers: {
70
- 'Content-Type': 'application/json',
71
- },
72
- });
73
-
74
- if(response.status === 200) {
75
- const responseJson = response.data;
76
-
77
- if (responseJson.uuid) {
78
- setUUID(responseJson.uuid);
79
- }
80
-
81
- if (responseJson?.show) {
82
- if (responseJson?.show) {
83
- const appearance_response = await setAppearance(
84
- responseJson,
85
- screen,
86
- state.domainName,
87
- traceId,
88
- variables
89
- );
90
- if (appearance_response) {
91
- isSpotPassed = true;
92
- spotcheckStateService.setState({ isSpotPassed });
93
- return { valid: true };
94
- }
95
- } else {
96
- throw new Error('');
97
- }
98
- }
99
-
100
- if (!isSpotPassed && responseJson?.checkPassed) {
101
- if (responseJson.checkCondition) {
102
- const checkCondition = responseJson.checkCondition;
103
- spotcheckStateService.setState({ afterDelay: checkCondition.afterDelay || 0 });
104
- if (checkCondition.customEvent) {
105
- spotcheckStateService.setState({ customEventsSpotChecks: [responseJson] });
106
- throw new Error('');
107
- }
108
- }
109
-
110
- const appearance_response = await setAppearance(
111
- responseJson,
112
- screen,
113
- state.domainName,
114
- traceId,
115
- variables
116
- );
117
- if (appearance_response) {
118
- isChecksPassed = true;
119
- spotcheckStateService.setState({ isChecksPassed });
120
- return { valid: true };
121
- }
122
- }
123
-
124
- if (!isSpotPassed && !isChecksPassed && responseJson?.multiShow != null) {
125
- if (responseJson.multiShow) {
126
- spotcheckStateService.setState({ customEventsSpotChecks: responseJson.resultantSpotCheck });
127
-
128
- let selectedSpotCheck = {};
129
- let minDelay: number = Number.POSITIVE_INFINITY;
130
-
131
- for (const spotcheck of responseJson.resultantSpotCheck) {
132
- const checks = spotcheck?.checks || {};
133
- if (Object.keys(checks).length === 0) {
134
- minDelay = 0;
135
- selectedSpotCheck = spotcheck;
136
- } else if (checks.afterDelay != null) {
137
- const delay = parseFloat(checks.afterDelay);
138
- if (minDelay > delay) {
139
- minDelay = delay;
140
- selectedSpotCheck = spotcheck;
141
- }
142
- }
143
- }
144
-
145
- if (Object.keys(selectedSpotCheck).length > 0) {
146
- spotcheckStateService.setState({ afterDelay: minDelay });
147
- const appearance_response = await setAppearance(
148
- selectedSpotCheck,
149
- screen,
150
- state.domainName,
151
- traceId,
152
- variables
153
- );
154
- if (appearance_response) {
155
- return { valid: true };
156
- }
157
- }
158
- }
159
- }
160
-
161
- throw new Error(responseJson?.reason?.toString() ?? 'Spotcheck conditions not met');
162
- } else {
163
- throw new Error(`Received status code ${response.status}`);
164
- }
165
- } catch (error: any) {
166
- return { valid: false, error: error.message };
167
- }
168
- };
169
-
170
-
171
- export const sendTrackEventRequest = async ({ screen, event }: TrackEventProps) => {
172
- try {
173
- const intMax = Number.POSITIVE_INFINITY;
174
- const state = getSpotcheckStateService().getState();
175
- let selectedSpotCheckID = intMax;
176
- let { isSpotPassed } = state;
177
- if (state.customEventsSpotChecks.length > 0) {
178
- const eventKeys = Object.keys(event);
179
- for (const spotCheck of state.customEventsSpotChecks) {
180
- const checks = spotCheck?.['checks'] ?? spotCheck?.['checkCondition'];
181
-
182
- if (checks) {
183
- const customEvent = checks?.customEvent;
184
-
185
- if (eventKeys.includes(customEvent?.eventName)) {
186
- selectedSpotCheckID =
187
- spotCheck?.['id'] ?? spotCheck?.['spotCheckId'] ?? intMax;
188
-
189
- if (selectedSpotCheckID !== intMax) {
190
- const payload = {
191
- screenName: screen,
192
- variables: state.variables,
193
- userDetails: state.screenwiseUserDetails[screen] || {},
194
- visitor: {
195
- deviceType: 'MOBILE',
196
- operatingSystem: await getOS(),
197
- screenResolution: {
198
- height: window.innerHeight,
199
- width: window.innerWidth,
200
- },
201
- currentDate: new Date().toISOString(),
202
- timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
203
- },
204
- spotCheckId: selectedSpotCheckID,
205
- eventTrigger: {
206
- customEvent: event,
207
- },
208
- traceId: state.traceId,
209
- customProperties: state.customProperties,
210
- };
211
-
212
- const url = `https://${state.domainName}/api/internal/spotcheck/widget/${state.targetToken}/eventTrigger?isSpotCheck=true`;
213
-
214
- try {
215
- const response = await axios.post<any>(url, payload, {
216
- headers: {
217
- 'Content-Type': 'application/json',
218
- },
219
- });
220
-
221
- if (response.status === 200) {
222
- const responseJson = response.data;
223
- if (responseJson?.show != null) {
224
- if (responseJson?.show) {
225
- const appearance_response = await setAppearance(
226
- responseJson,
227
- screen,
228
- state.domainName,
229
- state.traceId,
230
- state.variables
231
- );
232
-
233
- if (appearance_response) {
234
- getSpotcheckStateService().setState({ isSpotPassed: true });
235
- isSpotPassed = true;
236
- return { valid: true };
237
- }
238
- }
239
- }
240
-
241
- if (!isSpotPassed && responseJson?.eventShow) {
242
- if (responseJson?.checkCondition != null) {
243
- const checkCondition = responseJson?.checkCondition;
244
- getSpotcheckStateService().setState({
245
- afterDelay: checkCondition?.afterDelay ?? 0,
246
- });
247
-
248
- if (checkCondition?.customEvent != null) {
249
- getSpotcheckStateService().setState({
250
- afterDelay: checkCondition?.customEvent?.delayInSeconds ?? 0,
251
- });
252
- }
253
- }
254
-
255
- const appearance_response = await setAppearance(
256
- responseJson,
257
- screen,
258
- state.domainName,
259
- state.traceId,
260
- state.variables
261
- );
262
-
263
- if (appearance_response) {
264
- return { valid: true };
265
- }
266
- }
267
-
268
- throw new Error(responseJson?.reason?.toString() ?? 'Event conditions not met');
269
- } else {
270
- throw new Error(`Received status code ${response.status}`);
271
- }
272
- } catch (error: any) {
273
- throw new Error(error.message);
274
- }
275
- }
276
- }
277
- }
278
- }
279
- throw new Error('');
280
- } else {
281
- throw new Error('');
282
- }
283
- } catch (error: any) {
284
- return { valid: false, error: error.message };
285
- }
286
- };
@@ -1,414 +0,0 @@
1
- import { v4 as uuidv4 } from 'uuid';
2
- import { Device } from '@capacitor/device';
3
- import { SpotcheckState } from './types';
4
- import axios from 'axios';
5
- import { SpotcheckStateService } from './SpotcheckStateService';
6
- import { getSpotCheckEventListener } from './SpotCheckEventListener';
7
-
8
- let globalSpotcheckStateService: SpotcheckStateService;
9
- let globalOS: string | null = null;
10
-
11
- export const getSpotcheckStateService = (): SpotcheckStateService => {
12
- if (!globalSpotcheckStateService) {
13
- globalSpotcheckStateService = new SpotcheckStateService();
14
- }
15
- return globalSpotcheckStateService;
16
- };
17
-
18
- export function generateTraceId() {
19
- const uuidString = uuidv4();
20
- const timestamp = Date.now();
21
- return `${uuidString}-${timestamp}`;
22
- }
23
-
24
- export const ischatSurvey = (type: String) => {
25
- return (
26
- type === 'Conversational' ||
27
- type === 'CESChat' ||
28
- type === 'NPSChat' ||
29
- type === 'CSATChat'
30
- );
31
- };
32
-
33
- export const getOS = async () => {
34
- const info = await Device.getInfo();
35
- globalOS = info.operatingSystem;
36
- return globalOS;
37
- };
38
-
39
- export const setAppearance = async (
40
- responseJson: any,
41
- screen: string,
42
- domainName: string,
43
- traceId: string,
44
- variables: Record<string, any>
45
- ) => {
46
- try {
47
- const spotcheckStateService = getSpotcheckStateService();
48
- let state = spotcheckStateService.getState();
49
-
50
- if (responseJson) {
51
- const currentSpotcheck = state.filteredSpotChecks.find(
52
- (spotcheck) =>
53
- spotcheck['id'] === responseJson?.spotCheckId ||
54
- spotcheck['id'] === responseJson?.id
55
- );
56
-
57
- const appearance = responseJson?.appearance;
58
- let chat = false;
59
-
60
- let updatedState: Partial<SpotcheckState> = {};
61
-
62
- if (appearance) {
63
- const {
64
- position,
65
- closeButton,
66
- colors,
67
- cardProperties,
68
- mode,
69
- bannerImage,
70
- } = appearance;
71
- const { maxHeight } = cardProperties || {};
72
-
73
- updatedState = {
74
- spotcheckPosition:
75
- position === 'top_full' || position === 'center_top'
76
- ? 'top'
77
- : position === 'center_center'
78
- ? 'center'
79
- : 'bottom',
80
- isCloseButtonEnabled: closeButton ?? true,
81
- closeButtonStyle: colors?.overrides ?? {},
82
- maxHeight: maxHeight ? parseFloat(maxHeight) / 100 : 0,
83
- spotCheckType:
84
- ischatSurvey(currentSpotcheck?.['survey']?.surveyType) &&
85
- mode === 'fullScreen'
86
- ? 'chat'
87
- : 'classic',
88
- isFullScreenMode: mode === 'fullScreen',
89
- isBannerImageOn: bannerImage?.enabled ?? false,
90
- spotChecksMode: mode,
91
- avatarEnabled: appearance?.avatar?.enabled ?? false,
92
- avatarUrl: appearance?.avatar?.avatarUrl ?? '',
93
- };
94
-
95
- chat = updatedState.spotCheckType === 'chat';
96
- }
97
-
98
- const spotCheckId = responseJson?.spotCheckId ?? 0;
99
- const spotCheckContactId =
100
- responseJson?.spotCheckContactId ??
101
- responseJson?.spotCheckContact?.id ??
102
- 0;
103
- const triggerToken = responseJson?.triggerToken ?? '';
104
-
105
- updatedState = {
106
- ...updatedState,
107
- spotcheckID: spotCheckId,
108
- spotcheckContactID: spotCheckContactId,
109
- triggerToken,
110
- };
111
-
112
- const baseSpotcheckURL = `https://${domainName}/s/spotcheck/${triggerToken}/${
113
- chat ? 'config' : 'bootstrap'
114
- }?spotcheckContactId=${spotCheckContactId}&traceId=${traceId}&spotcheckUrl=${screen}`;
115
-
116
- let fullSpotcheckURL = baseSpotcheckURL;
117
-
118
- Object.entries(variables).forEach(([key, value]) => {
119
- fullSpotcheckURL += `&${key}=${value}`;
120
- });
121
-
122
- updatedState.spotcheckURL = fullSpotcheckURL;
123
- spotcheckStateService.setState(updatedState);
124
-
125
- try {
126
- const response = await axios.get<any>(fullSpotcheckURL);
127
- const themeInfo = response.data?.config?.generatedCSS;
128
- const theme_payload = { type: 'THEME_UPDATE_SPOTCHECK', themeInfo };
129
- state = spotcheckStateService.getState();
130
-
131
- let webViewRef = chat ? state.chatWebViewRef : state.classicWebViewRef;
132
- let isLoading = chat ? state.isChatLoading || !state.isChatLoadEventReceived : state.isClassicLoading || !state.isClassicLoadEventReceived;
133
-
134
- const resetStateData = {
135
- type: 'RESET_STATE',
136
- state: {
137
- ...(response.data || {}),
138
- skip: true,
139
- spotCheckAppearance: {
140
- ...(appearance || {}),
141
- targetType: 'MOBILE',
142
- },
143
- spotcheckUrl: screen,
144
- traceId,
145
- elementBuilderParams: {
146
- ...(variables || {}),
147
- },
148
- },
149
- };
150
-
151
- const sendMessageToIframe = (iframe: HTMLIFrameElement, data: any) => {
152
- if (iframe && iframe.contentWindow) {
153
- try {
154
- iframe.contentWindow.postMessage(data, '*');
155
- } catch (error) {
156
- console.error('❌ Failed to send message to iframe:', error);
157
- }
158
- }
159
- };
160
-
161
- const communicateWithWebView = async (iframe: HTMLIFrameElement) => {
162
- await new Promise(resolve => setTimeout(() => {
163
- sendMessageToIframe(iframe, resetStateData);
164
- sendMessageToIframe(iframe, theme_payload);
165
- resolve(true);
166
- }, 2000));
167
- };
168
-
169
- if (webViewRef) {
170
- if (isLoading === false) {
171
- communicateWithWebView(webViewRef);
172
- start();
173
- return true;
174
- } else {
175
- // todo: recheck this
176
- const unsubscribe = spotcheckStateService.state$.subscribe(
177
- (currentState) => {
178
- const {
179
- isChatLoading,
180
- isClassicLoading,
181
- chatWebViewRef,
182
- classicWebViewRef,
183
- isClassicLoadEventReceived,
184
- isChatLoadEventReceived,
185
- } = currentState;
186
-
187
-
188
- if ((!isChatLoading && chat && isChatLoadEventReceived) || (!isClassicLoading && !chat && isClassicLoadEventReceived)) {
189
- unsubscribe.unsubscribe();
190
- const activeWebViewRef = chat
191
- ? chatWebViewRef
192
- : classicWebViewRef;
193
- if (activeWebViewRef) {
194
- communicateWithWebView(activeWebViewRef);
195
- start();
196
- } else {
197
- console.warn(
198
- '⚠️ Active WebView ref is null after loading completed'
199
- );
200
- }
201
- }
202
- }
203
- );
204
- return true;
205
- }
206
- } else {
207
- const unsubscribeWebView = spotcheckStateService.state$.subscribe(
208
- (currentState) => {
209
- const updatedWebViewRef = chat
210
- ? currentState.chatWebViewRef
211
- : currentState.classicWebViewRef;
212
- const updatedIsLoading = chat
213
- ? currentState.isChatLoading || !currentState.isChatLoadEventReceived
214
- : currentState.isClassicLoading || !currentState.isClassicLoadEventReceived;
215
-
216
- if (updatedWebViewRef) {
217
- if (!updatedIsLoading) {
218
- unsubscribeWebView.unsubscribe();
219
- communicateWithWebView(updatedWebViewRef);
220
- start();
221
- } else {
222
- console.log('⏳ WebView ref available but still loading...');
223
- }
224
- }
225
- }
226
- );
227
- return true;
228
- }
229
- } catch (error: any) {
230
- throw new Error(error.message);
231
- }
232
- }
233
- throw new Error('Something went wrong');
234
- } catch (error: any) {
235
- throw new Error(error.message);
236
- }
237
- };
238
-
239
- export const start = () => {
240
- const state = getSpotcheckStateService().getState();
241
- setTimeout(() => {
242
- getSpotcheckStateService().setState({ isVisible: true });
243
- }, state.afterDelay * 1000);
244
- };
245
-
246
- export const closeSpotCheck = async () => {
247
- try {
248
- const stateService = getSpotcheckStateService();
249
- const state = stateService.getState();
250
- const payload = {
251
- traceId: state.traceId,
252
- triggerToken: state.triggerToken,
253
- };
254
-
255
- const response = await fetch(
256
- `https://${state.domainName}/api/internal/spotcheck/dismiss/${state.spotcheckContactID}`,
257
- {
258
- method: 'PUT',
259
- headers: {
260
- 'Content-Type': 'application/json',
261
- },
262
- body: JSON.stringify(payload),
263
- }
264
- );
265
- if(response.status == 200) {
266
- getSpotCheckEventListener().emit('surveyDismissed');
267
- }
268
- else{
269
- console.log(`Error: ${response.status}`);
270
- }
271
- } catch (error) {
272
- console.log('Error parsing JSON:', error);
273
- }
274
- };
275
-
276
- export const handleSurveyEnd = () => {
277
- const stateService = getSpotcheckStateService();
278
- const state = stateService.getState();
279
- const webViewRef =
280
- state.spotCheckType === 'chat'
281
- ? state.chatWebViewRef
282
- : state.classicWebViewRef;
283
-
284
- webViewRef?.current?.injectJavaScript(`
285
- (function() {
286
- window.dispatchEvent(new MessageEvent('message', {
287
- data: ${JSON.stringify({ type: 'UNMOUNT_APP' })}
288
- }));
289
- })();
290
- `);
291
-
292
- const updatedState: Partial<SpotcheckState> = {
293
- isVisible: false,
294
- isCloseButtonEnabled: false,
295
- isFullScreenMode: false,
296
- spotcheckID: 0,
297
- currentQuestionHeight: 0,
298
- closeButtonStyle: {},
299
- spotcheckContactID: 0,
300
- spotcheckURL: '',
301
- spotcheckPosition: 'bottom',
302
- isMounted: false,
303
- spotCheckType: '',
304
- screenHeight: 0,
305
- keyBoardHeight: 0,
306
- textPosition: 0,
307
- spotChecksMode: '',
308
- avatarEnabled: false,
309
- avatarUrl: '',
310
- };
311
-
312
- stateService.setState(updatedState);
313
- };
314
-
315
- export const getSpotcheckComponentCssStyles = (state: SpotcheckState) => {
316
- let styles = {}
317
- let wrapperStyles = {}
318
- let extraPaddingForMiniCardCloseButtonIfTopPosition = 0;
319
- if (state.isFullScreenMode && state.isVisible) {
320
- wrapperStyles = {
321
- display: 'flex',
322
- height: '100%',
323
- };
324
- styles = {
325
- display: 'flex',
326
- height: '100%',
327
- };
328
- }
329
-
330
- let marginBottom = globalOS !== 'ios' ? 18 : 0;
331
-
332
- if (state.isVisible && state.isMounted) {
333
-
334
- let height = Math.min(state.currentQuestionHeight, (state.maxHeight * window.innerHeight));
335
- if(state.spotChecksMode === 'miniCard') {
336
- if(state.avatarEnabled) {
337
- height = height - 56;
338
- if(state.spotcheckPosition === 'bottom') {
339
- marginBottom += 56;
340
- }
341
- }
342
- if(state.isCloseButtonEnabled) {
343
- height = height - 40;
344
- }
345
- }
346
-
347
- switch (state.spotcheckPosition) {
348
- case 'bottom':
349
- styles = {
350
- display: 'flex',
351
- height: height+'px',
352
- };
353
- wrapperStyles = {
354
- display: 'flex',
355
- justifyContent: 'flex-end',
356
- };
357
- break;
358
-
359
- case 'top':
360
- styles = {
361
- display: 'flex',
362
- height: height+'px',
363
- };
364
- wrapperStyles = {
365
- display: 'flex',
366
- justifyContent: 'flex-start',
367
- };
368
- if(state.spotChecksMode === 'miniCard' && state.isCloseButtonEnabled) {
369
- extraPaddingForMiniCardCloseButtonIfTopPosition = 30;
370
- }
371
- break;
372
-
373
- case 'center':
374
- styles = {
375
- display: 'flex',
376
- height: height+'px',
377
- };
378
- wrapperStyles = {
379
- display: 'flex',
380
- justifyContent: 'center',
381
- };
382
- break;
383
-
384
- default:
385
- break;
386
- }
387
- }
388
-
389
- return {
390
- wrapperStyles: {
391
- position: 'fixed',
392
- width: '100%',
393
- height: '100%',
394
- top: '0',
395
- left: '0',
396
- backgroundColor: 'rgba(0, 0, 0, 0.3)',
397
- zIndex: '100001',
398
- display: 'none',
399
- flexDirection: 'column',
400
- ...wrapperStyles
401
- },
402
- styles: {
403
- display: 'none',
404
- flexDirection: 'column',
405
- paddingTop: extraPaddingForMiniCardCloseButtonIfTopPosition+'px',
406
- marginBottom: marginBottom+'px',
407
- ...styles,
408
- }
409
- };
410
- };
411
-
412
- export const closeSpotCheckAndHandleSurveyEnd = async () => {
413
- handleSurveyEnd();
414
- };
@@ -1,7 +0,0 @@
1
- export const getStoredUUID = () => {
2
- return localStorage.getItem('SurveySparrowUUID') || null;
3
- }
4
-
5
- export const setUUID = (uuid: string) => {
6
- localStorage.setItem('SurveySparrowUUID', uuid);
7
- }