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.
- package/dist/angular-ui/fesm2022/angular-ui.mjs +1203 -998
- package/dist/angular-ui/fesm2022/angular-ui.mjs.map +1 -1
- package/dist/angular-ui/index.d.ts +119 -5
- package/dist/docs.json +13 -5
- package/dist/esm/angular-ui/lib/public-api.js.map +1 -1
- package/dist/esm/angular-ui/lib/spotcheck.component.d.ts +30 -1
- package/dist/esm/angular-ui/lib/spotcheck.component.js +194 -4
- package/dist/esm/angular-ui/lib/spotcheck.component.js.map +1 -1
- package/dist/esm/angular-ui/lib/spotchecks/components/builder.component.d.ts +57 -0
- package/dist/esm/angular-ui/lib/spotchecks/components/builder.component.js +284 -0
- package/dist/esm/angular-ui/lib/spotchecks/components/builder.component.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/binding.d.ts +25 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/binding.js +107 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/binding.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/device.d.ts +11 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/device.js +48 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/device.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/executables.d.ts +4 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/executables.js +113 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/executables.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/listener.d.ts +9 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/listener.js +55 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/listener.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/render.d.ts +5 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/render.js +43 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/render.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/sentry.d.ts +7 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/sentry.js +115 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/sentry.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/storage.d.ts +3 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/storage.js +40 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/storage.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/survey-page.d.ts +22 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/survey-page.js +128 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/survey-page.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/version.d.ts +2 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/version.js +4 -0
- package/dist/esm/angular-ui/lib/spotchecks/helpers/version.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/index.d.ts +4 -3
- package/dist/esm/angular-ui/lib/spotchecks/index.js +2 -2
- package/dist/esm/angular-ui/lib/spotchecks/index.js.map +1 -1
- package/dist/esm/angular-ui/lib/spotchecks/spotcheck.d.ts +8 -0
- package/dist/esm/angular-ui/lib/spotchecks/spotcheck.js +147 -0
- package/dist/esm/angular-ui/lib/spotchecks/spotcheck.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/state/store.d.ts +14 -0
- package/dist/esm/angular-ui/lib/spotchecks/state/store.js +109 -0
- package/dist/esm/angular-ui/lib/spotchecks/state/store.js.map +1 -0
- package/dist/esm/angular-ui/lib/spotchecks/types.d.ts +22 -58
- package/dist/esm/angular-ui/lib/spotchecks/types.js.map +1 -1
- package/dist/plugin.cjs.js +1211 -51762
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +1209 -51761
- package/dist/plugin.js.map +1 -1
- package/package.json +4 -8
- package/src/angular-ui/lib/public-api.ts +1 -1
- package/src/angular-ui/lib/spotcheck.component.ts +202 -5
- package/src/angular-ui/lib/spotchecks/components/builder.component.ts +254 -0
- package/src/angular-ui/lib/spotchecks/helpers/binding.ts +126 -0
- package/src/angular-ui/lib/spotchecks/helpers/device.ts +51 -0
- package/src/angular-ui/lib/spotchecks/helpers/executables.ts +124 -0
- package/src/angular-ui/lib/spotchecks/helpers/listener.ts +61 -0
- package/src/angular-ui/lib/spotchecks/helpers/render.ts +44 -0
- package/src/angular-ui/lib/spotchecks/helpers/sentry.ts +127 -0
- package/src/angular-ui/lib/spotchecks/helpers/storage.ts +37 -0
- package/src/angular-ui/lib/spotchecks/helpers/survey-page.ts +120 -0
- package/src/angular-ui/lib/spotchecks/helpers/version.ts +3 -0
- package/src/angular-ui/lib/spotchecks/index.ts +11 -3
- package/src/angular-ui/lib/spotchecks/spotcheck.ts +150 -0
- package/src/angular-ui/lib/spotchecks/state/store.ts +126 -0
- package/src/angular-ui/lib/spotchecks/types.ts +26 -59
- package/src/angular-ui/ng-package.json +9 -12
- package/src/angular-ui/package.json +9 -8
- package/dist/angular-ui/esm2022/angular-ui.mjs +0 -5
- package/dist/angular-ui/esm2022/public-api.mjs +0 -3
- package/dist/angular-ui/esm2022/spotcheck.component.mjs +0 -17
- package/dist/angular-ui/esm2022/spotchecks/SpotCheck.mjs +0 -51
- package/dist/angular-ui/esm2022/spotchecks/SpotCheckComponent.mjs +0 -410
- package/dist/angular-ui/esm2022/spotchecks/SpotCheckEventListener.mjs +0 -26
- package/dist/angular-ui/esm2022/spotchecks/SpotcheckStateService.mjs +0 -67
- package/dist/angular-ui/esm2022/spotchecks/api.mjs +0 -230
- package/dist/angular-ui/esm2022/spotchecks/helpers.mjs +0 -338
- package/dist/angular-ui/esm2022/spotchecks/index.mjs +0 -3
- package/dist/angular-ui/esm2022/spotchecks/storage.mjs +0 -7
- package/dist/angular-ui/esm2022/spotchecks/types.mjs +0 -2
- package/dist/angular-ui/public-api.d.ts +0 -2
- package/dist/angular-ui/spotcheck.component.d.ts +0 -5
- package/dist/angular-ui/spotchecks/SpotCheck.d.ts +0 -4
- package/dist/angular-ui/spotchecks/SpotCheckComponent.d.ts +0 -65
- package/dist/angular-ui/spotchecks/SpotCheckEventListener.d.ts +0 -16
- package/dist/angular-ui/spotchecks/SpotcheckStateService.d.ts +0 -12
- package/dist/angular-ui/spotchecks/api.d.ts +0 -15
- package/dist/angular-ui/spotchecks/helpers.d.ts +0 -30
- package/dist/angular-ui/spotchecks/index.d.ts +0 -3
- package/dist/angular-ui/spotchecks/storage.d.ts +0 -2
- package/dist/angular-ui/spotchecks/types.d.ts +0 -80
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheck.d.ts +0 -4
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheck.js +0 -51
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheck.js.map +0 -1
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckComponent.d.ts +0 -56
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckComponent.js +0 -397
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckComponent.js.map +0 -1
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckEventListener.d.ts +0 -16
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckEventListener.js +0 -28
- package/dist/esm/angular-ui/lib/spotchecks/SpotCheckEventListener.js.map +0 -1
- package/dist/esm/angular-ui/lib/spotchecks/SpotcheckStateService.d.ts +0 -9
- package/dist/esm/angular-ui/lib/spotchecks/SpotcheckStateService.js +0 -72
- package/dist/esm/angular-ui/lib/spotchecks/SpotcheckStateService.js.map +0 -1
- package/dist/esm/angular-ui/lib/spotchecks/api.d.ts +0 -15
- package/dist/esm/angular-ui/lib/spotchecks/api.js +0 -232
- package/dist/esm/angular-ui/lib/spotchecks/api.js.map +0 -1
- package/dist/esm/angular-ui/lib/spotchecks/helpers.d.ts +0 -30
- package/dist/esm/angular-ui/lib/spotchecks/helpers.js +0 -304
- package/dist/esm/angular-ui/lib/spotchecks/helpers.js.map +0 -1
- package/dist/esm/angular-ui/lib/spotchecks/storage.d.ts +0 -2
- package/dist/esm/angular-ui/lib/spotchecks/storage.js +0 -7
- package/dist/esm/angular-ui/lib/spotchecks/storage.js.map +0 -1
- package/src/angular-ui/lib/spotchecks/SpotCheck.ts +0 -54
- package/src/angular-ui/lib/spotchecks/SpotCheckComponent.css +0 -7
- package/src/angular-ui/lib/spotchecks/SpotCheckComponent.html +0 -27
- package/src/angular-ui/lib/spotchecks/SpotCheckComponent.ts +0 -389
- package/src/angular-ui/lib/spotchecks/SpotCheckEventListener.ts +0 -50
- package/src/angular-ui/lib/spotchecks/SpotcheckStateService.ts +0 -66
- package/src/angular-ui/lib/spotchecks/api.ts +0 -286
- package/src/angular-ui/lib/spotchecks/helpers.ts +0 -414
- package/src/angular-ui/lib/spotchecks/storage.ts +0 -7
|
@@ -1,1135 +1,1340 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
2
|
+
import { EventEmitter, Output, Directive, Input, Component, ViewEncapsulation, forwardRef, inject, ChangeDetectorRef, NgZone, PLATFORM_ID } from '@angular/core';
|
|
3
|
+
import { NgIf, NgFor, NgStyle, NgSwitch, NgSwitchCase, isPlatformBrowser } from '@angular/common';
|
|
4
|
+
import { Router, GuardsCheckEnd, NavigationEnd } from '@angular/router';
|
|
5
|
+
import { Subscription } from 'rxjs';
|
|
6
|
+
import { Capacitor } from '@capacitor/core';
|
|
6
7
|
import { Device } from '@capacitor/device';
|
|
7
|
-
import axios from 'axios';
|
|
8
|
-
import { BehaviorSubject, Subject } from 'rxjs';
|
|
9
|
-
import * as i1 from '@angular/platform-browser';
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
// Minimal observable store; components re-render on every change.
|
|
10
|
+
class Store {
|
|
11
|
+
state;
|
|
12
|
+
reducer;
|
|
13
|
+
listeners = new Set();
|
|
14
|
+
constructor(state, reducer) {
|
|
15
|
+
this.state = state;
|
|
16
|
+
this.reducer = reducer;
|
|
17
|
+
}
|
|
18
|
+
getState() {
|
|
19
|
+
return this.state;
|
|
20
|
+
}
|
|
21
|
+
dispatch(update) {
|
|
22
|
+
this.state = this.reducer(this.state, update);
|
|
23
|
+
this.listeners.forEach((listener) => {
|
|
24
|
+
try {
|
|
25
|
+
listener();
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
console.error('[SpotCheck] store listener failed', error);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
subscribe(listener) {
|
|
33
|
+
this.listeners.add(listener);
|
|
34
|
+
return () => {
|
|
35
|
+
this.listeners.delete(listener);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Same shape and merge rules as the other SDKs (backend functions read state.SpotCheckState).
|
|
40
|
+
const initialSpotcheckState = {
|
|
41
|
+
allSpotChecksInToken: [],
|
|
42
|
+
customEventsSpotChecks: [],
|
|
43
|
+
filteredSpotChecks: [],
|
|
44
|
+
showSpotCheck: false,
|
|
45
|
+
currentSpotcheck: {
|
|
15
46
|
spotcheckURL: '',
|
|
16
47
|
spotcheckID: 0,
|
|
17
48
|
spotcheckContactID: 0,
|
|
18
|
-
afterDelay: 0.0,
|
|
19
|
-
maxHeight: 0.5,
|
|
20
|
-
currentQuestionHeight: 0,
|
|
21
|
-
isFullScreenMode: false,
|
|
22
|
-
isBannerImageOn: false,
|
|
23
49
|
triggerToken: '',
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
50
|
+
screenName: '',
|
|
51
|
+
afterDelay: 0,
|
|
52
|
+
isChat: false,
|
|
53
|
+
appearance: {},
|
|
54
|
+
},
|
|
55
|
+
params: {
|
|
29
56
|
targetToken: '',
|
|
30
57
|
domainName: '',
|
|
31
58
|
userDetails: {},
|
|
32
59
|
variables: {},
|
|
33
60
|
customProperties: {},
|
|
61
|
+
visitor: {},
|
|
62
|
+
framework: 'ionic',
|
|
63
|
+
userAgent: '',
|
|
34
64
|
traceId: '',
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
isClassicLoadEventReceived: false,
|
|
38
|
-
isChatLoadEventReceived: false,
|
|
39
|
-
classicUrl: '',
|
|
40
|
-
chatUrl: '',
|
|
41
|
-
classicWebViewRef: null,
|
|
42
|
-
chatWebViewRef: null,
|
|
43
|
-
filteredSpotChecks: [],
|
|
44
|
-
spotCheckType: '',
|
|
45
|
-
isMounted: false,
|
|
46
|
-
textPosition: 0,
|
|
47
|
-
screenHeight: 0,
|
|
65
|
+
},
|
|
66
|
+
spotCheckDetails: {
|
|
48
67
|
keyBoardHeight: 0,
|
|
49
|
-
|
|
68
|
+
textPosition: 0,
|
|
69
|
+
isMounted: false,
|
|
70
|
+
isVisible: false,
|
|
71
|
+
isExiting: false,
|
|
72
|
+
currentQuestionHeight: 0,
|
|
73
|
+
miniCardHeight: 0,
|
|
74
|
+
sideTabButtonWidth: 0,
|
|
75
|
+
isFullScreenMode: false,
|
|
76
|
+
spotCheckType: null,
|
|
77
|
+
position: 'bottom',
|
|
78
|
+
mode: '',
|
|
79
|
+
closeButton: {
|
|
80
|
+
isEnabled: false,
|
|
81
|
+
color: '#000000',
|
|
82
|
+
isMiniCard: false,
|
|
83
|
+
},
|
|
84
|
+
isSpotCheckButton: false,
|
|
85
|
+
spotCheckButtonConfig: {},
|
|
86
|
+
showSurveyContent: true,
|
|
50
87
|
avatarEnabled: false,
|
|
51
88
|
avatarUrl: '',
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
89
|
+
isRTLLanguage: false,
|
|
90
|
+
},
|
|
91
|
+
webViewDetails: {
|
|
92
|
+
isChatEnabled: false,
|
|
93
|
+
isClassicEnabled: false,
|
|
94
|
+
isClassicLoading: true,
|
|
95
|
+
isChatLoading: true,
|
|
96
|
+
chatUrl: null,
|
|
97
|
+
classicUrl: null,
|
|
98
|
+
isCurrentSpotcheckChat: null,
|
|
99
|
+
canShowClassic: false,
|
|
100
|
+
canShowChat: false,
|
|
101
|
+
webViewInjectionData: null,
|
|
102
|
+
chatWebViewRef: null,
|
|
103
|
+
classicWebViewRef: null,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
const NESTED_KEYS = ['currentSpotcheck', 'spotCheckDetails', 'webViewDetails', 'params'];
|
|
107
|
+
const spotcheckReducer = (state, update) => {
|
|
108
|
+
const payload = update || {};
|
|
109
|
+
const sc = state.SpotCheckState;
|
|
110
|
+
const next = { ...sc, ...payload };
|
|
111
|
+
NESTED_KEYS.forEach((key) => {
|
|
112
|
+
next[key] = { ...sc[key], ...(payload[key] || {}) };
|
|
113
|
+
});
|
|
114
|
+
return { SpotCheckState: next };
|
|
115
|
+
};
|
|
116
|
+
const spotcheckStore = new Store({ SpotCheckState: initialSpotcheckState }, spotcheckReducer);
|
|
117
|
+
const functionStore = new Store({ functionState: { isLoaded: false } }, (state, update) => ({ functionState: { ...state.functionState, ...(update || {}) } }));
|
|
118
|
+
const componentStore = new Store({ componentState: { isLoaded: false, schemas: {} } }, (state, update) => ({ componentState: { ...state.componentState, ...(update || {}) } }));
|
|
119
|
+
|
|
120
|
+
// Keep in sync with package.json "version".
|
|
121
|
+
const SDK_VERSION = '2.1.0';
|
|
122
|
+
const FRAMEWORK = 'ionic';
|
|
123
|
+
|
|
124
|
+
// SDK errors go to SurveySparrow's API (backend sentry.processSentryError), never to Sentry servers.
|
|
125
|
+
// Set by executables.ts at load time (avoids a circular import).
|
|
126
|
+
let executeRef = null;
|
|
127
|
+
const registerExecute = (fn) => {
|
|
128
|
+
executeRef = fn;
|
|
129
|
+
};
|
|
130
|
+
const MAX_BREADCRUMBS = 30;
|
|
131
|
+
const sdkBreadcrumbs = [];
|
|
132
|
+
const addBreadcrumb = (message, data) => {
|
|
133
|
+
sdkBreadcrumbs.push({ category: 'spotcheck', message, data, timestamp: Date.now() / 1000 });
|
|
134
|
+
if (sdkBreadcrumbs.length > MAX_BREADCRUMBS)
|
|
135
|
+
sdkBreadcrumbs.shift();
|
|
136
|
+
};
|
|
137
|
+
const MAX_BREADCRUMB_STRING = 200;
|
|
138
|
+
const capString = (value) => value.slice(0, MAX_BREADCRUMB_STRING);
|
|
139
|
+
// Breadcrumb hook for backend functions; drops bad input and never throws.
|
|
140
|
+
const safeAddBreadcrumb = (message, data) => {
|
|
141
|
+
try {
|
|
142
|
+
if (typeof message !== 'string')
|
|
143
|
+
return;
|
|
144
|
+
let clean;
|
|
145
|
+
const proto = data && typeof data === 'object' ? Object.getPrototypeOf(data) : undefined;
|
|
146
|
+
if (proto === Object.prototype || proto === null) {
|
|
147
|
+
clean = {};
|
|
148
|
+
Object.keys(data).forEach((key) => {
|
|
149
|
+
const value = data[key];
|
|
150
|
+
if (typeof value === 'string')
|
|
151
|
+
clean[key] = capString(value);
|
|
152
|
+
else if (value === null || typeof value === 'number' || typeof value === 'boolean')
|
|
153
|
+
clean[key] = value;
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
addBreadcrumb(capString(message), clean);
|
|
157
|
+
}
|
|
158
|
+
catch { }
|
|
159
|
+
};
|
|
160
|
+
// Flags an error as reported so execute() does not report it again.
|
|
161
|
+
const markReported = (error) => {
|
|
162
|
+
try {
|
|
163
|
+
if (error !== null && typeof error === 'object') {
|
|
164
|
+
Object.defineProperty(error, '__ssReported', { value: true, configurable: true });
|
|
165
|
+
}
|
|
58
166
|
}
|
|
59
|
-
|
|
60
|
-
|
|
167
|
+
catch { }
|
|
168
|
+
};
|
|
169
|
+
const isReported = (error) => {
|
|
170
|
+
try {
|
|
171
|
+
return !!error?.__ssReported;
|
|
61
172
|
}
|
|
62
|
-
|
|
63
|
-
return
|
|
173
|
+
catch {
|
|
174
|
+
return false;
|
|
64
175
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
176
|
+
};
|
|
177
|
+
// Routes an event to the backend; never throws.
|
|
178
|
+
const sendToBackend = async (normalizedEvent) => {
|
|
179
|
+
try {
|
|
180
|
+
const result = executeRef
|
|
181
|
+
? await executeRef('sentry.processSentryError', {
|
|
182
|
+
event: normalizedEvent,
|
|
183
|
+
sdkType: FRAMEWORK,
|
|
184
|
+
sdkVersion: SDK_VERSION,
|
|
185
|
+
})
|
|
186
|
+
: null;
|
|
187
|
+
if (result)
|
|
188
|
+
return;
|
|
189
|
+
const { domainName, targetToken } = spotcheckStore.getState().SpotCheckState?.params || {};
|
|
190
|
+
if (!domainName)
|
|
191
|
+
return;
|
|
192
|
+
await fetch(`https://${domainName}/api/internal/spotcheck/sdkErrors`, {
|
|
193
|
+
method: 'POST',
|
|
194
|
+
headers: { 'Content-Type': 'application/json' },
|
|
195
|
+
body: JSON.stringify({
|
|
196
|
+
errorMessage: normalizedEvent.errorMessage,
|
|
197
|
+
sdkType: FRAMEWORK,
|
|
198
|
+
sdkVersion: SDK_VERSION,
|
|
199
|
+
level: normalizedEvent.tags?.error_priority === 'P0' ? 'fatal' : 'error',
|
|
200
|
+
tags: normalizedEvent.tags,
|
|
201
|
+
extra: normalizedEvent.extra,
|
|
202
|
+
breadcrumbs: normalizedEvent.breadcrumbs,
|
|
203
|
+
contexts: { user: { spotcheck_token: targetToken || '', spotcheck_domain_name: domainName } },
|
|
204
|
+
}),
|
|
205
|
+
}).catch(() => { });
|
|
206
|
+
}
|
|
207
|
+
catch {
|
|
208
|
+
// Reporting must never break the host app.
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
const report = (error, priority, source, extra) => {
|
|
212
|
+
markReported(error);
|
|
213
|
+
const err = error;
|
|
214
|
+
sendToBackend({
|
|
215
|
+
errorMessage: err?.message || String(error),
|
|
216
|
+
tags: {
|
|
217
|
+
error_priority: priority,
|
|
218
|
+
severity: priority === 'P0' ? 'CRITICAL' : 'HIGH',
|
|
219
|
+
errorType: source,
|
|
220
|
+
},
|
|
221
|
+
contexts: {},
|
|
222
|
+
extra: extra || {},
|
|
223
|
+
breadcrumbs: [...sdkBreadcrumbs],
|
|
224
|
+
exceptions: [{
|
|
225
|
+
type: err?.name || 'Error',
|
|
226
|
+
value: err?.message || String(error),
|
|
227
|
+
stack: String(err?.stack || '').slice(0, 2000),
|
|
228
|
+
}],
|
|
229
|
+
timestamp: Date.now() / 1000,
|
|
230
|
+
platform: 'javascript',
|
|
231
|
+
});
|
|
232
|
+
};
|
|
233
|
+
const captureP0Error = (error, source, extra) => report(error, 'P0', source, extra);
|
|
234
|
+
const captureP1Error = (error, source, extra) => report(error, 'P1', source, extra);
|
|
74
235
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
236
|
+
// Same key as the legacy Ionic SDK, so existing installs keep their visitor.
|
|
237
|
+
const UUID_KEY = 'SurveySparrowUUID';
|
|
238
|
+
const uuidV4 = () => {
|
|
239
|
+
const c = typeof crypto !== 'undefined' ? crypto : null;
|
|
240
|
+
if (c?.randomUUID)
|
|
241
|
+
return c.randomUUID();
|
|
242
|
+
const bytes = new Uint8Array(16);
|
|
243
|
+
if (c?.getRandomValues)
|
|
244
|
+
c.getRandomValues(bytes);
|
|
245
|
+
else
|
|
246
|
+
for (let i = 0; i < 16; i++)
|
|
247
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
248
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
249
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
250
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
|
|
251
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
252
|
+
};
|
|
253
|
+
const generateTraceId = () => `${uuidV4()}-${Date.now()}`;
|
|
254
|
+
const saveData = async (value) => {
|
|
255
|
+
try {
|
|
256
|
+
localStorage.setItem(UUID_KEY, value);
|
|
87
257
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
258
|
+
catch (error) {
|
|
259
|
+
captureP1Error(error, 'GENERAL', { action: 'saveData', errorMessage: error?.message });
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
// isuuid: a new trace id; otherwise the stored visitor UUID.
|
|
263
|
+
const loadData = async (isuuid = false) => {
|
|
264
|
+
try {
|
|
265
|
+
if (isuuid)
|
|
266
|
+
return generateTraceId();
|
|
267
|
+
return localStorage.getItem(UUID_KEY) || null;
|
|
268
|
+
}
|
|
269
|
+
catch (error) {
|
|
270
|
+
captureP1Error(error, 'GENERAL', { action: 'loadData', isuuid, errorMessage: error?.message });
|
|
271
|
+
return null;
|
|
93
272
|
}
|
|
94
|
-
return globalInstance;
|
|
95
273
|
};
|
|
274
|
+
|
|
275
|
+
const legacyCallbacks = new Map();
|
|
276
|
+
const emit = (type, data) => {
|
|
277
|
+
legacyCallbacks.get(type)?.forEach((callback) => {
|
|
278
|
+
try {
|
|
279
|
+
runInApp(() => callback(data));
|
|
280
|
+
}
|
|
281
|
+
catch (error) {
|
|
282
|
+
console.error(`[SpotCheck] ${type} listener failed`, error);
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
// Returns an RxJS Subscription, as the legacy SDK did.
|
|
96
287
|
const addSpotCheckListener = (eventType, callback) => {
|
|
97
|
-
|
|
288
|
+
if (!legacyCallbacks.has(eventType))
|
|
289
|
+
legacyCallbacks.set(eventType, new Set());
|
|
290
|
+
legacyCallbacks.get(eventType).add(callback);
|
|
291
|
+
return new Subscription(() => {
|
|
292
|
+
legacyCallbacks.get(eventType)?.delete(callback);
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
let appListener = {};
|
|
296
|
+
// Set by <SpotCheck>: runs app callbacks inside the Angular zone.
|
|
297
|
+
let runInApp = (fn) => fn();
|
|
298
|
+
const setAppRunner = (runner) => {
|
|
299
|
+
runInApp = runner;
|
|
300
|
+
};
|
|
301
|
+
const setListener = (listener) => {
|
|
302
|
+
appListener = listener || {};
|
|
303
|
+
};
|
|
304
|
+
// What backend functions call: the app's listener first, then the legacy events.
|
|
305
|
+
const sdkListener = {
|
|
306
|
+
onSurveyLoaded: async (data) => {
|
|
307
|
+
await runInApp(() => appListener.onSurveyLoaded?.(data));
|
|
308
|
+
// 2.0.3 passed surveyDetails.
|
|
309
|
+
emit('surveyLoadStarted', data?.['surveyDetails'] ?? data);
|
|
310
|
+
},
|
|
311
|
+
onSurveyResponse: async (data) => {
|
|
312
|
+
await runInApp(() => appListener.onSurveyResponse?.(data));
|
|
313
|
+
// Legacy Ionic passed the response array.
|
|
314
|
+
emit('surveyCompleted', data?.['response'] ?? data);
|
|
315
|
+
},
|
|
316
|
+
onPartialSubmission: async (data) => {
|
|
317
|
+
await runInApp(() => appListener.onPartialSubmission?.(data));
|
|
318
|
+
},
|
|
319
|
+
onCloseButtonTap: async () => {
|
|
320
|
+
await runInApp(() => appListener.onCloseButtonTap?.());
|
|
321
|
+
emit('surveyDismissed');
|
|
322
|
+
},
|
|
98
323
|
};
|
|
99
324
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
325
|
+
const dispatchWrapper = (stateUpdate) => {
|
|
326
|
+
try {
|
|
327
|
+
spotcheckStore.dispatch(stateUpdate);
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
captureP1Error(error, 'GENERAL', { action: 'dispatchWrapper', errorMessage: error?.message });
|
|
105
331
|
}
|
|
106
|
-
return globalSpotcheckStateService;
|
|
107
332
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
type === 'CSATChat');
|
|
333
|
+
const pendingExecutes = [];
|
|
334
|
+
const MAX_PENDING_EXECUTES = 20;
|
|
335
|
+
const isTrackScreenOrEvent = (functionName) => functionName === 'trackScreen' || functionName === 'trackEvent';
|
|
336
|
+
const flushPendingExecutes = async () => {
|
|
337
|
+
while (pendingExecutes.length > 0) {
|
|
338
|
+
const item = pendingExecutes.shift();
|
|
339
|
+
if (item)
|
|
340
|
+
await execute(item.functionName, item.params);
|
|
341
|
+
}
|
|
118
342
|
};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
343
|
+
// Track calls wait until initializeSpotcheckComponent has finished.
|
|
344
|
+
let isInitialized = false;
|
|
345
|
+
const markInitialized = async () => {
|
|
346
|
+
isInitialized = true;
|
|
347
|
+
await flushPendingExecutes();
|
|
123
348
|
};
|
|
124
|
-
|
|
349
|
+
// Reporting failures are not reported again (avoids loops).
|
|
350
|
+
const isSentryFunction = (functionName) => functionName.startsWith('sentry.');
|
|
351
|
+
// Style getters run on every render; they would push useful breadcrumbs out.
|
|
352
|
+
const isBreadcrumbWorthy = (functionName) => !isSentryFunction(functionName) && !/\.get\w*Styles$/.test(functionName);
|
|
353
|
+
// Message type only; never survey content.
|
|
354
|
+
const describeParams = (functionName, params) => {
|
|
355
|
+
if (functionName !== 'webviewComponent.handleWebViewMessage')
|
|
356
|
+
return {};
|
|
125
357
|
try {
|
|
126
|
-
|
|
127
|
-
let state = spotcheckStateService.getState();
|
|
128
|
-
if (responseJson) {
|
|
129
|
-
const currentSpotcheck = state.filteredSpotChecks.find((spotcheck) => spotcheck['id'] === responseJson?.spotCheckId ||
|
|
130
|
-
spotcheck['id'] === responseJson?.id);
|
|
131
|
-
const appearance = responseJson?.appearance;
|
|
132
|
-
let chat = false;
|
|
133
|
-
let updatedState = {};
|
|
134
|
-
if (appearance) {
|
|
135
|
-
const { position, closeButton, colors, cardProperties, mode, bannerImage, } = appearance;
|
|
136
|
-
const { maxHeight } = cardProperties || {};
|
|
137
|
-
updatedState = {
|
|
138
|
-
spotcheckPosition: position === 'top_full' || position === 'center_top'
|
|
139
|
-
? 'top'
|
|
140
|
-
: position === 'center_center'
|
|
141
|
-
? 'center'
|
|
142
|
-
: 'bottom',
|
|
143
|
-
isCloseButtonEnabled: closeButton ?? true,
|
|
144
|
-
closeButtonStyle: colors?.overrides ?? {},
|
|
145
|
-
maxHeight: maxHeight ? parseFloat(maxHeight) / 100 : 0,
|
|
146
|
-
spotCheckType: ischatSurvey(currentSpotcheck?.['survey']?.surveyType) &&
|
|
147
|
-
mode === 'fullScreen'
|
|
148
|
-
? 'chat'
|
|
149
|
-
: 'classic',
|
|
150
|
-
isFullScreenMode: mode === 'fullScreen',
|
|
151
|
-
isBannerImageOn: bannerImage?.enabled ?? false,
|
|
152
|
-
spotChecksMode: mode,
|
|
153
|
-
avatarEnabled: appearance?.avatar?.enabled ?? false,
|
|
154
|
-
avatarUrl: appearance?.avatar?.avatarUrl ?? '',
|
|
155
|
-
};
|
|
156
|
-
chat = updatedState.spotCheckType === 'chat';
|
|
157
|
-
}
|
|
158
|
-
const spotCheckId = responseJson?.spotCheckId ?? 0;
|
|
159
|
-
const spotCheckContactId = responseJson?.spotCheckContactId ??
|
|
160
|
-
responseJson?.spotCheckContact?.id ??
|
|
161
|
-
0;
|
|
162
|
-
const triggerToken = responseJson?.triggerToken ?? '';
|
|
163
|
-
updatedState = {
|
|
164
|
-
...updatedState,
|
|
165
|
-
spotcheckID: spotCheckId,
|
|
166
|
-
spotcheckContactID: spotCheckContactId,
|
|
167
|
-
triggerToken,
|
|
168
|
-
};
|
|
169
|
-
const baseSpotcheckURL = `https://${domainName}/s/spotcheck/${triggerToken}/${chat ? 'config' : 'bootstrap'}?spotcheckContactId=${spotCheckContactId}&traceId=${traceId}&spotcheckUrl=${screen}`;
|
|
170
|
-
let fullSpotcheckURL = baseSpotcheckURL;
|
|
171
|
-
Object.entries(variables).forEach(([key, value]) => {
|
|
172
|
-
fullSpotcheckURL += `&${key}=${value}`;
|
|
173
|
-
});
|
|
174
|
-
updatedState.spotcheckURL = fullSpotcheckURL;
|
|
175
|
-
spotcheckStateService.setState(updatedState);
|
|
176
|
-
try {
|
|
177
|
-
const response = await axios.get(fullSpotcheckURL);
|
|
178
|
-
const themeInfo = response.data?.config?.generatedCSS;
|
|
179
|
-
const theme_payload = { type: 'THEME_UPDATE_SPOTCHECK', themeInfo };
|
|
180
|
-
state = spotcheckStateService.getState();
|
|
181
|
-
let webViewRef = chat ? state.chatWebViewRef : state.classicWebViewRef;
|
|
182
|
-
let isLoading = chat ? state.isChatLoading || !state.isChatLoadEventReceived : state.isClassicLoading || !state.isClassicLoadEventReceived;
|
|
183
|
-
const resetStateData = {
|
|
184
|
-
type: 'RESET_STATE',
|
|
185
|
-
state: {
|
|
186
|
-
...(response.data || {}),
|
|
187
|
-
skip: true,
|
|
188
|
-
spotCheckAppearance: {
|
|
189
|
-
...(appearance || {}),
|
|
190
|
-
targetType: 'MOBILE',
|
|
191
|
-
},
|
|
192
|
-
spotcheckUrl: screen,
|
|
193
|
-
traceId,
|
|
194
|
-
elementBuilderParams: {
|
|
195
|
-
...(variables || {}),
|
|
196
|
-
},
|
|
197
|
-
},
|
|
198
|
-
};
|
|
199
|
-
const sendMessageToIframe = (iframe, data) => {
|
|
200
|
-
if (iframe && iframe.contentWindow) {
|
|
201
|
-
try {
|
|
202
|
-
iframe.contentWindow.postMessage(data, '*');
|
|
203
|
-
}
|
|
204
|
-
catch (error) {
|
|
205
|
-
console.error('❌ Failed to send message to iframe:', error);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
const communicateWithWebView = async (iframe) => {
|
|
210
|
-
await new Promise(resolve => setTimeout(() => {
|
|
211
|
-
sendMessageToIframe(iframe, resetStateData);
|
|
212
|
-
sendMessageToIframe(iframe, theme_payload);
|
|
213
|
-
resolve(true);
|
|
214
|
-
}, 2000));
|
|
215
|
-
};
|
|
216
|
-
if (webViewRef) {
|
|
217
|
-
if (isLoading === false) {
|
|
218
|
-
communicateWithWebView(webViewRef);
|
|
219
|
-
start();
|
|
220
|
-
return true;
|
|
221
|
-
}
|
|
222
|
-
else {
|
|
223
|
-
// todo: recheck this
|
|
224
|
-
const unsubscribe = spotcheckStateService.state$.subscribe((currentState) => {
|
|
225
|
-
const { isChatLoading, isClassicLoading, chatWebViewRef, classicWebViewRef, isClassicLoadEventReceived, isChatLoadEventReceived, } = currentState;
|
|
226
|
-
if ((!isChatLoading && chat && isChatLoadEventReceived) || (!isClassicLoading && !chat && isClassicLoadEventReceived)) {
|
|
227
|
-
unsubscribe.unsubscribe();
|
|
228
|
-
const activeWebViewRef = chat
|
|
229
|
-
? chatWebViewRef
|
|
230
|
-
: classicWebViewRef;
|
|
231
|
-
if (activeWebViewRef) {
|
|
232
|
-
communicateWithWebView(activeWebViewRef);
|
|
233
|
-
start();
|
|
234
|
-
}
|
|
235
|
-
else {
|
|
236
|
-
console.warn('⚠️ Active WebView ref is null after loading completed');
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
return true;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
const unsubscribeWebView = spotcheckStateService.state$.subscribe((currentState) => {
|
|
245
|
-
const updatedWebViewRef = chat
|
|
246
|
-
? currentState.chatWebViewRef
|
|
247
|
-
: currentState.classicWebViewRef;
|
|
248
|
-
const updatedIsLoading = chat
|
|
249
|
-
? currentState.isChatLoading || !currentState.isChatLoadEventReceived
|
|
250
|
-
: currentState.isClassicLoading || !currentState.isClassicLoadEventReceived;
|
|
251
|
-
if (updatedWebViewRef) {
|
|
252
|
-
if (!updatedIsLoading) {
|
|
253
|
-
unsubscribeWebView.unsubscribe();
|
|
254
|
-
communicateWithWebView(updatedWebViewRef);
|
|
255
|
-
start();
|
|
256
|
-
}
|
|
257
|
-
else {
|
|
258
|
-
console.log('⏳ WebView ref available but still loading...');
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
});
|
|
262
|
-
return true;
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
catch (error) {
|
|
266
|
-
throw new Error(error.message);
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
throw new Error('Something went wrong');
|
|
358
|
+
return { messageType: JSON.parse(params?.event?.nativeEvent?.data)?.type };
|
|
270
359
|
}
|
|
271
|
-
catch
|
|
272
|
-
|
|
360
|
+
catch {
|
|
361
|
+
return {};
|
|
273
362
|
}
|
|
274
363
|
};
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
364
|
+
const lookup = (functionName) => {
|
|
365
|
+
let current = functionStore.getState().functionState;
|
|
366
|
+
for (const part of functionName.split('.'))
|
|
367
|
+
current = current?.[part];
|
|
368
|
+
return current;
|
|
369
|
+
};
|
|
370
|
+
// True when the backend sent this function (dotted path), e.g. for schema `$execute`.
|
|
371
|
+
const hasFunction = (functionName) => typeof lookup(functionName) === 'string';
|
|
372
|
+
// The SDK has no native keyboard mode to change; the overlay follows the keyboard instead.
|
|
373
|
+
const keyboard = {
|
|
374
|
+
pauseDefaultKeyboardBehavior: () => { },
|
|
375
|
+
resumeDefaultKeyboardBehavior: () => { },
|
|
280
376
|
};
|
|
281
|
-
const
|
|
377
|
+
const execute = async (functionName, params) => {
|
|
378
|
+
let func;
|
|
379
|
+
let payload;
|
|
282
380
|
try {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
381
|
+
if (isTrackScreenOrEvent(functionName) && !isInitialized) {
|
|
382
|
+
pendingExecutes.push({ functionName, params });
|
|
383
|
+
// Cap the queue while init keeps failing; oldest calls go first.
|
|
384
|
+
if (pendingExecutes.length > MAX_PENDING_EXECUTES)
|
|
385
|
+
pendingExecutes.shift();
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
if (!functionStore.getState().functionState.isLoaded)
|
|
389
|
+
return null;
|
|
390
|
+
const functionString = lookup(functionName);
|
|
391
|
+
if (!functionString || typeof functionString !== 'string') {
|
|
392
|
+
console.error(`Function ${functionName} not found`);
|
|
393
|
+
return null;
|
|
394
|
+
}
|
|
395
|
+
payload = {
|
|
396
|
+
params: { ...params, sdkVersion: SDK_VERSION },
|
|
397
|
+
state: spotcheckStore.getState(),
|
|
398
|
+
dispatchWrapper,
|
|
399
|
+
storage: { saveData, loadData },
|
|
400
|
+
listener: sdkListener,
|
|
401
|
+
sentry: { captureP0Error, captureP1Error, addBreadcrumb: safeAddBreadcrumb },
|
|
402
|
+
keyboard,
|
|
288
403
|
};
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (
|
|
297
|
-
|
|
404
|
+
// Fresh evaluation per call like the other SDKs; indirect eval keeps it in global scope.
|
|
405
|
+
func = (0, eval)(`(${functionString})`);
|
|
406
|
+
if (isBreadcrumbWorthy(functionName)) {
|
|
407
|
+
addBreadcrumb('execute', { functionName, ...describeParams(functionName, params) });
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
catch (error) {
|
|
411
|
+
if (isSentryFunction(functionName))
|
|
412
|
+
return null;
|
|
413
|
+
captureP1Error(error, 'GENERAL', { action: 'execute:setup', functionName, errorMessage: error?.message });
|
|
414
|
+
return null;
|
|
415
|
+
}
|
|
416
|
+
try {
|
|
417
|
+
return await func(payload);
|
|
418
|
+
}
|
|
419
|
+
catch (error) {
|
|
420
|
+
if (isSentryFunction(functionName))
|
|
421
|
+
return null;
|
|
422
|
+
// Skip when the function already reported this error itself.
|
|
423
|
+
if (!isReported(error)) {
|
|
424
|
+
captureP1Error(error, 'GENERAL', { action: 'execute:runtime', functionName, errorMessage: error?.message });
|
|
298
425
|
}
|
|
299
|
-
|
|
300
|
-
|
|
426
|
+
console.error(`[execute] ${functionName}:`, error);
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
registerExecute(execute);
|
|
431
|
+
|
|
432
|
+
// Loads the survey page from its own domain in a separate-origin iframe (as in 2.0.3), so the
|
|
433
|
+
// page can never reach the host app. The SDK and the page talk only through postMessage.
|
|
434
|
+
// Runs a backend injection with a stand-in window and keeps only the messages it dispatches.
|
|
435
|
+
// Scripts that touch the page DOM (CSS, re-measure) cannot cross origins and are dropped, as in 2.0.3.
|
|
436
|
+
const messagesFromScript = (script) => {
|
|
437
|
+
const messages = [];
|
|
438
|
+
const pageWindow = {
|
|
439
|
+
dispatchEvent: (event) => {
|
|
440
|
+
if (event?.data != null)
|
|
441
|
+
messages.push(event.data);
|
|
442
|
+
return true;
|
|
443
|
+
},
|
|
444
|
+
};
|
|
445
|
+
class PageMessageEvent {
|
|
446
|
+
type;
|
|
447
|
+
data;
|
|
448
|
+
constructor(type, init) {
|
|
449
|
+
this.type = type;
|
|
450
|
+
this.data = init?.data;
|
|
301
451
|
}
|
|
302
452
|
}
|
|
453
|
+
try {
|
|
454
|
+
// The host globals are shadowed so a DOM script fails here instead of touching the app.
|
|
455
|
+
new Function('window', 'MessageEvent', 'document', 'self', 'globalThis', 'parent', 'top', script)(pageWindow, PageMessageEvent, undefined, pageWindow, pageWindow, pageWindow, pageWindow);
|
|
456
|
+
}
|
|
457
|
+
catch {
|
|
458
|
+
// DOM-only script: nothing to send.
|
|
459
|
+
}
|
|
460
|
+
return messages;
|
|
461
|
+
};
|
|
462
|
+
// Same list as the survey page (rtls).
|
|
463
|
+
const RTL_LANGUAGES = ['ar', 'he', 'fa', 'ps', 'ur'];
|
|
464
|
+
// The web page sends its fields at the top level; the backend reads the RN/Expo shape { type, data }.
|
|
465
|
+
const toBackendMessage = (message) => {
|
|
466
|
+
if (!message || typeof message !== 'object' || typeof message.type !== 'string')
|
|
467
|
+
return null;
|
|
468
|
+
if (message.type === 'resizeWindow') {
|
|
469
|
+
const height = message.size?.height;
|
|
470
|
+
return typeof height === 'number' ? { type: 'spotCheckData', data: { currentQuestionSize: { height } } } : null;
|
|
471
|
+
}
|
|
472
|
+
if ('data' in message)
|
|
473
|
+
return message;
|
|
474
|
+
const { type, ...data } = message;
|
|
475
|
+
// The web languageChanged has only the code; add isRtl from the page's own RTL list.
|
|
476
|
+
if (type === 'languageChanged' && typeof data.code === 'string') {
|
|
477
|
+
data.isRtl = RTL_LANGUAGES.includes(data.code.split(/[-_]/)[0].toLowerCase());
|
|
478
|
+
}
|
|
479
|
+
return { type, data };
|
|
480
|
+
};
|
|
481
|
+
class SurveyPage {
|
|
482
|
+
callbacks;
|
|
483
|
+
iframe;
|
|
484
|
+
uri = '';
|
|
485
|
+
origin = '';
|
|
486
|
+
loadSeq = 0;
|
|
487
|
+
onWindowMessage = (event) => {
|
|
488
|
+
// Only the survey page in this iframe, from the survey domain.
|
|
489
|
+
if (event.source !== this.iframe.contentWindow || event.origin !== this.origin)
|
|
490
|
+
return;
|
|
491
|
+
const message = toBackendMessage(event.data);
|
|
492
|
+
if (message)
|
|
493
|
+
this.callbacks.onMessage(JSON.stringify(message));
|
|
494
|
+
};
|
|
495
|
+
constructor(host, callbacks) {
|
|
496
|
+
this.callbacks = callbacks;
|
|
497
|
+
this.iframe = document.createElement('iframe');
|
|
498
|
+
this.iframe.setAttribute('title', 'Survey');
|
|
499
|
+
this.iframe.setAttribute('allow', 'camera; microphone; geolocation; display-capture; autoplay; clipboard-read; clipboard-write; fullscreen');
|
|
500
|
+
this.iframe.setAttribute('allowfullscreen', '');
|
|
501
|
+
this.iframe.style.cssText = 'display:block;width:100%;height:100%;border:0;background:transparent;';
|
|
502
|
+
host.appendChild(this.iframe);
|
|
503
|
+
window.addEventListener('message', this.onWindowMessage);
|
|
504
|
+
}
|
|
505
|
+
load(uri) {
|
|
506
|
+
if (!uri || uri === this.uri)
|
|
507
|
+
return;
|
|
508
|
+
this.uri = uri;
|
|
509
|
+
this.origin = new URL(uri).origin;
|
|
510
|
+
const seq = ++this.loadSeq;
|
|
511
|
+
// A cross-origin iframe hides HTTP errors, so check the page first to report a failed load.
|
|
512
|
+
fetch(uri, { credentials: 'omit' })
|
|
513
|
+
.then((response) => {
|
|
514
|
+
if (!response.ok)
|
|
515
|
+
throw new Error(`Survey page failed with status ${response.status}`);
|
|
516
|
+
if (seq === this.loadSeq)
|
|
517
|
+
this.iframe.src = uri;
|
|
518
|
+
})
|
|
519
|
+
.catch((error) => {
|
|
520
|
+
if (seq !== this.loadSeq)
|
|
521
|
+
return;
|
|
522
|
+
// A later load() with the same uri retries.
|
|
523
|
+
this.uri = '';
|
|
524
|
+
const description = error?.message || String(error);
|
|
525
|
+
// message: readable text for the Sentry report (the RN event shape has none).
|
|
526
|
+
this.callbacks.onError({ nativeEvent: { url: uri, description }, message: description });
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
// Same contract as the RN WebView ref the backend functions call; messages go by postMessage.
|
|
530
|
+
injectJavaScript = (script) => {
|
|
531
|
+
const win = this.iframe.contentWindow;
|
|
532
|
+
if (!win || !this.origin)
|
|
533
|
+
return false;
|
|
534
|
+
const messages = messagesFromScript(script);
|
|
535
|
+
messages.forEach((data) => {
|
|
536
|
+
win.postMessage(data, this.origin);
|
|
537
|
+
// 2.0.3 sent the theme right after the survey state; the web page needs it to apply survey colours.
|
|
538
|
+
const themeInfo = data?.type === 'RESET_STATE' ? data.state?.config?.generatedCSS : null;
|
|
539
|
+
if (themeInfo)
|
|
540
|
+
win.postMessage({ type: 'THEME_UPDATE_SPOTCHECK', themeInfo }, this.origin);
|
|
541
|
+
});
|
|
542
|
+
return messages.length > 0;
|
|
543
|
+
};
|
|
544
|
+
destroy() {
|
|
545
|
+
this.loadSeq++;
|
|
546
|
+
window.removeEventListener('message', this.onWindowMessage);
|
|
547
|
+
this.iframe.remove();
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// Render guard, like RN's error boundary: a failed draw hides SpotCheck, the app keeps running,
|
|
552
|
+
// and it is reported once as APP_CRASH.
|
|
553
|
+
let crashed = false;
|
|
554
|
+
const crashListeners = new Set();
|
|
555
|
+
const hasCrashed = () => crashed;
|
|
556
|
+
const onCrash = (listener) => {
|
|
557
|
+
crashListeners.add(listener);
|
|
558
|
+
return () => {
|
|
559
|
+
crashListeners.delete(listener);
|
|
560
|
+
};
|
|
561
|
+
};
|
|
562
|
+
const guardedDetectChanges = (cdr, action) => {
|
|
563
|
+
if (crashed)
|
|
564
|
+
return;
|
|
565
|
+
try {
|
|
566
|
+
cdr.detectChanges();
|
|
567
|
+
}
|
|
303
568
|
catch (error) {
|
|
304
|
-
|
|
569
|
+
crashed = true;
|
|
570
|
+
captureP0Error(error, 'APP_CRASH', { action, errorMessage: error?.message });
|
|
571
|
+
crashListeners.forEach((listener) => {
|
|
572
|
+
try {
|
|
573
|
+
listener();
|
|
574
|
+
}
|
|
575
|
+
catch { }
|
|
576
|
+
});
|
|
305
577
|
}
|
|
306
578
|
};
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
})
|
|
318
|
-
})();
|
|
319
|
-
`);
|
|
320
|
-
const updatedState = {
|
|
321
|
-
isVisible: false,
|
|
322
|
-
isCloseButtonEnabled: false,
|
|
323
|
-
isFullScreenMode: false,
|
|
324
|
-
spotcheckID: 0,
|
|
325
|
-
currentQuestionHeight: 0,
|
|
326
|
-
closeButtonStyle: {},
|
|
327
|
-
spotcheckContactID: 0,
|
|
328
|
-
spotcheckURL: '',
|
|
329
|
-
spotcheckPosition: 'bottom',
|
|
330
|
-
isMounted: false,
|
|
331
|
-
spotCheckType: '',
|
|
332
|
-
screenHeight: 0,
|
|
333
|
-
keyBoardHeight: 0,
|
|
334
|
-
textPosition: 0,
|
|
335
|
-
spotChecksMode: '',
|
|
336
|
-
avatarEnabled: false,
|
|
337
|
-
avatarUrl: '',
|
|
579
|
+
// Runs fn once per microtask however often it is requested (many dispatches, one render).
|
|
580
|
+
const batched = (fn) => {
|
|
581
|
+
let queued = false;
|
|
582
|
+
return () => {
|
|
583
|
+
if (queued)
|
|
584
|
+
return;
|
|
585
|
+
queued = true;
|
|
586
|
+
queueMicrotask(() => {
|
|
587
|
+
queued = false;
|
|
588
|
+
fn();
|
|
589
|
+
});
|
|
338
590
|
};
|
|
339
|
-
stateService.setState(updatedState);
|
|
340
591
|
};
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
592
|
+
|
|
593
|
+
// Same binding rules as the other SDKs' Builder.
|
|
594
|
+
const evaluateExpression = (expr, context) => {
|
|
595
|
+
try {
|
|
596
|
+
const safeContext = { state: context.state, styles: context.styles, Math };
|
|
597
|
+
const func = new Function(...Object.keys(safeContext), `return ${expr}`);
|
|
598
|
+
return func(...Object.values(safeContext));
|
|
599
|
+
}
|
|
600
|
+
catch (error) {
|
|
601
|
+
captureP1Error(error, 'GENERAL', {
|
|
602
|
+
action: 'evaluateExpression',
|
|
603
|
+
expression: expr?.substring(0, 200),
|
|
604
|
+
errorMessage: error?.message,
|
|
605
|
+
});
|
|
606
|
+
return undefined;
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
const readPath = (root, path) => {
|
|
610
|
+
let result = root;
|
|
611
|
+
for (const key of path.split('.'))
|
|
612
|
+
result = result?.[key];
|
|
613
|
+
return result;
|
|
614
|
+
};
|
|
615
|
+
const resolveBinding = (value, context) => {
|
|
616
|
+
if (!value || typeof value !== 'object')
|
|
617
|
+
return value;
|
|
618
|
+
if (Array.isArray(value))
|
|
619
|
+
return value.map((item) => resolveBinding(item, context));
|
|
620
|
+
if (value.$expr)
|
|
621
|
+
return evaluateExpression(value.$expr, context);
|
|
622
|
+
if (value.$ref)
|
|
623
|
+
return readPath(context, value.$ref);
|
|
624
|
+
if (value.$path)
|
|
625
|
+
return readPath(context.state, value.$path);
|
|
626
|
+
if (value.$handler && context.handlers)
|
|
627
|
+
return context.handlers[value.$handler];
|
|
628
|
+
// Generic action: `{ $execute: 'group.fn', args: {...} }` runs a backend function; unknown names do nothing.
|
|
629
|
+
if (typeof value.$execute === 'string') {
|
|
630
|
+
const functionName = value.$execute;
|
|
631
|
+
const args = value.args && typeof value.args === 'object' ? value.args : {};
|
|
632
|
+
return (event) => {
|
|
633
|
+
if (!functionName || !hasFunction(functionName))
|
|
634
|
+
return;
|
|
635
|
+
const nativeEvent = event?.nativeEvent;
|
|
636
|
+
const eventData = nativeEvent && typeof nativeEvent === 'object' ? { ...nativeEvent } : undefined;
|
|
637
|
+
execute(functionName, eventData ? { ...args, event: eventData } : { ...args }).catch(() => { });
|
|
349
638
|
};
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
639
|
+
}
|
|
640
|
+
if (Array.isArray(value.$handlers) && context.handlers) {
|
|
641
|
+
return (...args) => {
|
|
642
|
+
value.$handlers.forEach((name) => context.handlers?.[name]?.(...args));
|
|
353
643
|
};
|
|
354
644
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
645
|
+
const resolved = {};
|
|
646
|
+
for (const key in value)
|
|
647
|
+
resolved[key] = resolveBinding(value[key], context);
|
|
648
|
+
return resolved;
|
|
649
|
+
};
|
|
650
|
+
const pair = (cond, op, context) => cond[op].map((val) => resolveBinding(val, context));
|
|
651
|
+
const evaluateCondition = (condition, context) => {
|
|
652
|
+
if (!condition)
|
|
653
|
+
return true;
|
|
654
|
+
if (typeof condition === 'object' && !Array.isArray(condition)) {
|
|
655
|
+
if (Array.isArray(condition.$and))
|
|
656
|
+
return condition.$and.every((c) => evaluateCondition(c, context));
|
|
657
|
+
if (Array.isArray(condition.$or))
|
|
658
|
+
return condition.$or.some((c) => evaluateCondition(c, context));
|
|
659
|
+
if (condition.$not !== undefined)
|
|
660
|
+
return !evaluateCondition(condition.$not, context);
|
|
661
|
+
if (Array.isArray(condition.$eq) && condition.$eq.length === 2) {
|
|
662
|
+
const [l, r] = pair(condition, '$eq', context);
|
|
663
|
+
return l === r;
|
|
368
664
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
display: 'flex',
|
|
373
|
-
height: height + 'px',
|
|
374
|
-
};
|
|
375
|
-
wrapperStyles = {
|
|
376
|
-
display: 'flex',
|
|
377
|
-
justifyContent: 'flex-end',
|
|
378
|
-
};
|
|
379
|
-
break;
|
|
380
|
-
case 'top':
|
|
381
|
-
styles = {
|
|
382
|
-
display: 'flex',
|
|
383
|
-
height: height + 'px',
|
|
384
|
-
};
|
|
385
|
-
wrapperStyles = {
|
|
386
|
-
display: 'flex',
|
|
387
|
-
justifyContent: 'flex-start',
|
|
388
|
-
};
|
|
389
|
-
if (state.spotChecksMode === 'miniCard' && state.isCloseButtonEnabled) {
|
|
390
|
-
extraPaddingForMiniCardCloseButtonIfTopPosition = 30;
|
|
391
|
-
}
|
|
392
|
-
break;
|
|
393
|
-
case 'center':
|
|
394
|
-
styles = {
|
|
395
|
-
display: 'flex',
|
|
396
|
-
height: height + 'px',
|
|
397
|
-
};
|
|
398
|
-
wrapperStyles = {
|
|
399
|
-
display: 'flex',
|
|
400
|
-
justifyContent: 'center',
|
|
401
|
-
};
|
|
402
|
-
break;
|
|
403
|
-
default:
|
|
404
|
-
break;
|
|
665
|
+
if (Array.isArray(condition.$ne) && condition.$ne.length === 2) {
|
|
666
|
+
const [l, r] = pair(condition, '$ne', context);
|
|
667
|
+
return l !== r;
|
|
405
668
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
position: 'fixed',
|
|
410
|
-
width: '100%',
|
|
411
|
-
height: '100%',
|
|
412
|
-
top: '0',
|
|
413
|
-
left: '0',
|
|
414
|
-
backgroundColor: 'rgba(0, 0, 0, 0.3)',
|
|
415
|
-
zIndex: '100001',
|
|
416
|
-
display: 'none',
|
|
417
|
-
flexDirection: 'column',
|
|
418
|
-
...wrapperStyles
|
|
419
|
-
},
|
|
420
|
-
styles: {
|
|
421
|
-
display: 'none',
|
|
422
|
-
flexDirection: 'column',
|
|
423
|
-
paddingTop: extraPaddingForMiniCardCloseButtonIfTopPosition + 'px',
|
|
424
|
-
marginBottom: marginBottom + 'px',
|
|
425
|
-
...styles,
|
|
669
|
+
if (Array.isArray(condition.$gt) && condition.$gt.length === 2) {
|
|
670
|
+
const [l, r] = pair(condition, '$gt', context);
|
|
671
|
+
return l > r;
|
|
426
672
|
}
|
|
427
|
-
|
|
673
|
+
if (Array.isArray(condition.$lt) && condition.$lt.length === 2) {
|
|
674
|
+
const [l, r] = pair(condition, '$lt', context);
|
|
675
|
+
return l < r;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
return Boolean(resolveBinding(condition, context));
|
|
428
679
|
};
|
|
429
|
-
|
|
430
|
-
|
|
680
|
+
// CSS properties that take plain numbers; every other number is px.
|
|
681
|
+
const UNITLESS = new Set([
|
|
682
|
+
'opacity', 'zIndex', 'flex', 'flexGrow', 'flexShrink', 'fontWeight', 'order', 'aspectRatio', 'scale',
|
|
683
|
+
]);
|
|
684
|
+
// Backend styles are CSS objects with camelCase keys.
|
|
685
|
+
const toCss = (style) => {
|
|
686
|
+
if (!style || typeof style !== 'object' || Array.isArray(style))
|
|
687
|
+
return null;
|
|
688
|
+
const css = {};
|
|
689
|
+
for (const key of Object.keys(style)) {
|
|
690
|
+
const value = style[key];
|
|
691
|
+
if (value == null || typeof value === 'object')
|
|
692
|
+
continue;
|
|
693
|
+
css[key] = typeof value === 'number' && !UNITLESS.has(key) ? `${value}px` : String(value);
|
|
694
|
+
}
|
|
695
|
+
return css;
|
|
431
696
|
};
|
|
432
697
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
this.sanitizer = sanitizer;
|
|
444
|
-
this.ngZone = ngZone;
|
|
445
|
-
this.cdr = cdr;
|
|
698
|
+
// Reports the element's untransformed width like RN onLayout ({ nativeEvent: { layout } }).
|
|
699
|
+
class LayoutDirective {
|
|
700
|
+
el;
|
|
701
|
+
zone;
|
|
702
|
+
ssLayout = new EventEmitter();
|
|
703
|
+
observer;
|
|
704
|
+
last = '';
|
|
705
|
+
constructor(el, zone) {
|
|
706
|
+
this.el = el;
|
|
707
|
+
this.zone = zone;
|
|
446
708
|
}
|
|
447
709
|
ngOnInit() {
|
|
448
|
-
if (
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
else {
|
|
462
|
-
stateService.setState({
|
|
463
|
-
chatWebViewRef: webViewRef,
|
|
464
|
-
isChatLoading: false,
|
|
465
|
-
});
|
|
466
|
-
}
|
|
467
|
-
this.setupIframeLoadListener();
|
|
468
|
-
}
|
|
469
|
-
setupIframeLoadListener() {
|
|
470
|
-
const iframe = this.iframe.nativeElement;
|
|
471
|
-
iframe.addEventListener('load', () => {
|
|
472
|
-
this.ngZone.run(() => {
|
|
473
|
-
this.injectNativeBridgeAdapters(iframe);
|
|
474
|
-
const stateService = getSpotcheckStateService();
|
|
475
|
-
if (this.webviewType === 'classic') {
|
|
476
|
-
stateService.setState({ isClassicLoading: false });
|
|
477
|
-
}
|
|
478
|
-
else {
|
|
479
|
-
stateService.setState({ isChatLoading: false });
|
|
480
|
-
}
|
|
710
|
+
if (typeof ResizeObserver === 'undefined')
|
|
711
|
+
return;
|
|
712
|
+
this.zone.runOutsideAngular(() => {
|
|
713
|
+
this.observer = new ResizeObserver(() => {
|
|
714
|
+
const node = this.el.nativeElement;
|
|
715
|
+
const layout = { x: node.offsetLeft, y: node.offsetTop, width: node.offsetWidth, height: node.offsetHeight };
|
|
716
|
+
const key = `${layout.width}x${layout.height}`;
|
|
717
|
+
if (key === this.last)
|
|
718
|
+
return;
|
|
719
|
+
this.last = key;
|
|
720
|
+
this.ssLayout.emit({ nativeEvent: { layout } });
|
|
481
721
|
});
|
|
722
|
+
this.observer.observe(this.el.nativeElement);
|
|
482
723
|
});
|
|
483
724
|
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
}
|
|
520
|
-
|
|
725
|
+
ngOnDestroy() {
|
|
726
|
+
this.observer?.disconnect();
|
|
727
|
+
}
|
|
728
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.34", ngImport: i0, type: LayoutDirective, deps: [{ token: i0.ElementRef }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
|
|
729
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "20.3.34", type: LayoutDirective, isStandalone: true, selector: "[ssLayout]", outputs: { ssLayout: "ssLayout" }, ngImport: i0 });
|
|
730
|
+
}
|
|
731
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.34", ngImport: i0, type: LayoutDirective, decorators: [{
|
|
732
|
+
type: Directive,
|
|
733
|
+
args: [{ selector: '[ssLayout]', standalone: true }]
|
|
734
|
+
}], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.NgZone }], propDecorators: { ssLayout: [{
|
|
735
|
+
type: Output
|
|
736
|
+
}] } });
|
|
737
|
+
// Hosts one survey page; mirrors the RN WebViewRenderer (hidden pages stay 1x1 off-screen and keep loading).
|
|
738
|
+
class WebViewRendererComponent {
|
|
739
|
+
el;
|
|
740
|
+
uri = '';
|
|
741
|
+
canShow = false;
|
|
742
|
+
onMessage;
|
|
743
|
+
onError;
|
|
744
|
+
refCallback;
|
|
745
|
+
hostStyle = '';
|
|
746
|
+
page;
|
|
747
|
+
constructor(el) {
|
|
748
|
+
this.el = el;
|
|
749
|
+
}
|
|
750
|
+
ngOnChanges() {
|
|
751
|
+
this.hostStyle = this.canShow
|
|
752
|
+
? 'display:block;position:relative;width:100%;height:100%;'
|
|
753
|
+
: 'display:block;position:absolute;left:-1000px;top:0;width:1px;height:1px;opacity:0;overflow:hidden;';
|
|
754
|
+
if (!this.uri)
|
|
755
|
+
return;
|
|
756
|
+
if (!this.page) {
|
|
757
|
+
this.page = new SurveyPage(this.el.nativeElement, {
|
|
758
|
+
onMessage: (data) => this.onMessage?.({ nativeEvent: { data } }),
|
|
759
|
+
onError: (error) => this.onError?.(error),
|
|
760
|
+
});
|
|
761
|
+
this.refCallback?.(this.page);
|
|
521
762
|
}
|
|
763
|
+
this.page.load(this.uri);
|
|
522
764
|
}
|
|
523
|
-
|
|
524
|
-
this.
|
|
525
|
-
|
|
526
|
-
const { data } = event;
|
|
527
|
-
switch (data.type) {
|
|
528
|
-
case 'slideInFrame':
|
|
529
|
-
if (data.mounted) {
|
|
530
|
-
stateService.setState({ isMounted: true });
|
|
531
|
-
}
|
|
532
|
-
break;
|
|
533
|
-
case 'resizeWindow':
|
|
534
|
-
if (data.size) {
|
|
535
|
-
stateService.setState({
|
|
536
|
-
currentQuestionHeight: data.size.height,
|
|
537
|
-
});
|
|
538
|
-
}
|
|
539
|
-
else if (data.isCloseButtonEnabled) {
|
|
540
|
-
stateService.setState({
|
|
541
|
-
isCloseButtonEnabled: data.isCloseButtonEnabled,
|
|
542
|
-
});
|
|
543
|
-
}
|
|
544
|
-
break;
|
|
545
|
-
case 'surveyCompleted':
|
|
546
|
-
closeSpotCheckAndHandleSurveyEnd().then(() => {
|
|
547
|
-
getSpotCheckEventListener().emit('surveyCompleted', data.response);
|
|
548
|
-
this.cdr.detectChanges();
|
|
549
|
-
});
|
|
550
|
-
break;
|
|
551
|
-
case 'surveyLoadStarted':
|
|
552
|
-
getSpotCheckEventListener().emit('surveyLoadStarted', data.surveyDetails);
|
|
553
|
-
break;
|
|
554
|
-
case 'classicLoadEvent':
|
|
555
|
-
stateService.setState({ isClassicLoadEventReceived: true });
|
|
556
|
-
break;
|
|
557
|
-
case 'chatLoadEvent':
|
|
558
|
-
stateService.setState({ isChatLoadEventReceived: true });
|
|
559
|
-
break;
|
|
560
|
-
default:
|
|
561
|
-
break;
|
|
562
|
-
}
|
|
563
|
-
this.cdr.detectChanges();
|
|
564
|
-
});
|
|
765
|
+
ngOnDestroy() {
|
|
766
|
+
this.refCallback?.(null);
|
|
767
|
+
this.page?.destroy();
|
|
565
768
|
}
|
|
566
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.
|
|
567
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.
|
|
568
|
-
<div style="overflow: hidden; height: 100%; border-radius: {{isMiniCard ? 12 : 0}}px; padding-left: {{isMiniCard ? 12 : 0}}px; padding-right: {{isMiniCard ? 12 : 0}}px; box-sizing: border-box;">
|
|
569
|
-
<iframe
|
|
570
|
-
allow="camera; microphone; geolocation; display-capture; autoplay; clipboard-read; clipboard-write; fullscreen"
|
|
571
|
-
allowfullscreen
|
|
572
|
-
#iframeRef
|
|
573
|
-
[src]="safeUrl"
|
|
574
|
-
style="width: 100%; height: 100%; display: block; border-radius: {{isMiniCard ? 12 : 0}}px;"
|
|
575
|
-
frameborder="0"
|
|
576
|
-
>
|
|
577
|
-
</iframe>
|
|
578
|
-
</div>
|
|
579
|
-
`, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }] });
|
|
769
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.34", ngImport: i0, type: WebViewRendererComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
770
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.34", type: WebViewRendererComponent, isStandalone: true, selector: "ss-webview-renderer", inputs: { uri: "uri", canShow: "canShow", onMessage: "onMessage", onError: "onError", refCallback: "refCallback" }, host: { properties: { "style": "hostStyle" } }, usesOnChanges: true, ngImport: i0, template: '', isInline: true });
|
|
580
771
|
}
|
|
581
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.
|
|
772
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.34", ngImport: i0, type: WebViewRendererComponent, decorators: [{
|
|
582
773
|
type: Component,
|
|
583
774
|
args: [{
|
|
584
|
-
selector: '
|
|
585
|
-
template: `
|
|
586
|
-
<div style="overflow: hidden; height: 100%; border-radius: {{isMiniCard ? 12 : 0}}px; padding-left: {{isMiniCard ? 12 : 0}}px; padding-right: {{isMiniCard ? 12 : 0}}px; box-sizing: border-box;">
|
|
587
|
-
<iframe
|
|
588
|
-
allow="camera; microphone; geolocation; display-capture; autoplay; clipboard-read; clipboard-write; fullscreen"
|
|
589
|
-
allowfullscreen
|
|
590
|
-
#iframeRef
|
|
591
|
-
[src]="safeUrl"
|
|
592
|
-
style="width: 100%; height: 100%; display: block; border-radius: {{isMiniCard ? 12 : 0}}px;"
|
|
593
|
-
frameborder="0"
|
|
594
|
-
>
|
|
595
|
-
</iframe>
|
|
596
|
-
</div>
|
|
597
|
-
`,
|
|
775
|
+
selector: 'ss-webview-renderer',
|
|
598
776
|
standalone: true,
|
|
599
|
-
|
|
777
|
+
template: '',
|
|
778
|
+
host: { '[style]': 'hostStyle' },
|
|
600
779
|
}]
|
|
601
|
-
}], ctorParameters: () => [{ type:
|
|
602
|
-
type: Input
|
|
603
|
-
}], webviewType: [{
|
|
780
|
+
}], ctorParameters: () => [{ type: i0.ElementRef }], propDecorators: { uri: [{
|
|
604
781
|
type: Input
|
|
605
|
-
}],
|
|
782
|
+
}], canShow: [{
|
|
606
783
|
type: Input
|
|
607
|
-
}], iframe: [{
|
|
608
|
-
type: ViewChild,
|
|
609
|
-
args: ['iframeRef']
|
|
610
784
|
}], onMessage: [{
|
|
611
|
-
type: HostListener,
|
|
612
|
-
args: ['window:message', ['$event']]
|
|
613
|
-
}] } });
|
|
614
|
-
class CloseSVGComponent {
|
|
615
|
-
size = 32;
|
|
616
|
-
stroke = '#919191';
|
|
617
|
-
strokeWidth = 1.5;
|
|
618
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.3", ngImport: i0, type: CloseSVGComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
619
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.3", type: CloseSVGComponent, isStandalone: true, selector: "close-svg", inputs: { size: "size", stroke: "stroke", strokeWidth: "strokeWidth" }, ngImport: i0, template: `
|
|
620
|
-
<svg
|
|
621
|
-
[attr.width]="size"
|
|
622
|
-
[attr.height]="size"
|
|
623
|
-
viewBox="0 0 32 32"
|
|
624
|
-
fill="none"
|
|
625
|
-
xmlns="https://www.w3.org/2000/svg"
|
|
626
|
-
>
|
|
627
|
-
<path
|
|
628
|
-
d="M10.6665 10.667L21.3332 21.3337M21.3332 10.667L10.6665 21.3337"
|
|
629
|
-
[attr.stroke]="stroke"
|
|
630
|
-
[attr.stroke-width]="strokeWidth"
|
|
631
|
-
stroke-linecap="round"
|
|
632
|
-
stroke-linejoin="round"
|
|
633
|
-
/>
|
|
634
|
-
</svg>
|
|
635
|
-
`, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }] });
|
|
636
|
-
}
|
|
637
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.3", ngImport: i0, type: CloseSVGComponent, decorators: [{
|
|
638
|
-
type: Component,
|
|
639
|
-
args: [{
|
|
640
|
-
selector: 'close-svg',
|
|
641
|
-
template: `
|
|
642
|
-
<svg
|
|
643
|
-
[attr.width]="size"
|
|
644
|
-
[attr.height]="size"
|
|
645
|
-
viewBox="0 0 32 32"
|
|
646
|
-
fill="none"
|
|
647
|
-
xmlns="https://www.w3.org/2000/svg"
|
|
648
|
-
>
|
|
649
|
-
<path
|
|
650
|
-
d="M10.6665 10.667L21.3332 21.3337M21.3332 10.667L10.6665 21.3337"
|
|
651
|
-
[attr.stroke]="stroke"
|
|
652
|
-
[attr.stroke-width]="strokeWidth"
|
|
653
|
-
stroke-linecap="round"
|
|
654
|
-
stroke-linejoin="round"
|
|
655
|
-
/>
|
|
656
|
-
</svg>
|
|
657
|
-
`,
|
|
658
|
-
standalone: true,
|
|
659
|
-
imports: [CommonModule],
|
|
660
|
-
}]
|
|
661
|
-
}], propDecorators: { size: [{
|
|
662
785
|
type: Input
|
|
663
|
-
}],
|
|
786
|
+
}], onError: [{
|
|
664
787
|
type: Input
|
|
665
|
-
}],
|
|
788
|
+
}], refCallback: [{
|
|
666
789
|
type: Input
|
|
667
790
|
}] } });
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
this.
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
this.ngZone.run(() => {
|
|
690
|
-
this.state = newState;
|
|
691
|
-
this.updateComponentState();
|
|
692
|
-
this.cdr.detectChanges();
|
|
693
|
-
});
|
|
694
|
-
});
|
|
695
|
-
}
|
|
696
|
-
ngOnDestroy() {
|
|
697
|
-
if (this.stateSubscription) {
|
|
698
|
-
this.stateSubscription.unsubscribe();
|
|
791
|
+
// Renders one backend schema node as HTML (same node rules as the other SDKs' Builder).
|
|
792
|
+
class SsNodeComponent {
|
|
793
|
+
node;
|
|
794
|
+
ctx = {};
|
|
795
|
+
visible = false;
|
|
796
|
+
kind = '';
|
|
797
|
+
role = null;
|
|
798
|
+
props = {};
|
|
799
|
+
css = null;
|
|
800
|
+
content = null;
|
|
801
|
+
slot = null;
|
|
802
|
+
svgSrc = '';
|
|
803
|
+
children = [];
|
|
804
|
+
// Binding results are computed once per render so templates see stable values.
|
|
805
|
+
ngOnChanges() {
|
|
806
|
+
const node = this.node;
|
|
807
|
+
const ctx = this.ctx || {};
|
|
808
|
+
this.slot = null;
|
|
809
|
+
if (!node) {
|
|
810
|
+
this.visible = false;
|
|
811
|
+
return;
|
|
699
812
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
this.
|
|
704
|
-
|
|
705
|
-
(this.state.isFullScreenMode &&
|
|
706
|
-
((!this.state.isClassicLoading &&
|
|
707
|
-
this.state.spotCheckType === 'classic') ||
|
|
708
|
-
(!this.state.isChatLoading &&
|
|
709
|
-
this.state.spotCheckType === 'chat'))));
|
|
710
|
-
this.isMiniCard = this.state.spotChecksMode === 'miniCard';
|
|
711
|
-
this.stroke = this.isMiniCard ? 'black' : this.state.closeButtonStyle?.['ctaButton'] || 'black';
|
|
712
|
-
if (this.isVisible) {
|
|
713
|
-
this.isClosing = false;
|
|
813
|
+
if (node.slot) {
|
|
814
|
+
this.kind = 'slot';
|
|
815
|
+
this.slot = ctx.slots?.[node.slot] || null;
|
|
816
|
+
this.visible = Boolean(this.slot);
|
|
817
|
+
return;
|
|
714
818
|
}
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
if (this.isClosing) {
|
|
819
|
+
this.visible = node.if === undefined || evaluateCondition(node.if, ctx);
|
|
820
|
+
if (!this.visible)
|
|
718
821
|
return;
|
|
822
|
+
this.kind = node.type || '';
|
|
823
|
+
this.role = node.meta?.componentRole || null;
|
|
824
|
+
this.props = node.props ? resolveBinding(node.props, ctx) || {} : {};
|
|
825
|
+
this.css = toCss(this.props['style']);
|
|
826
|
+
this.content = node.content !== undefined ? resolveBinding(node.content, ctx) : null;
|
|
827
|
+
this.children = node.children || [];
|
|
828
|
+
if (this.kind === 'SvgXml') {
|
|
829
|
+
const xml = typeof this.props['xml'] === 'string' ? this.props['xml'] : '';
|
|
830
|
+
// As an image, so markup in the icon can never run script.
|
|
831
|
+
this.svgSrc = xml ? `data:image/svg+xml;charset=utf-8,${encodeURIComponent(xml)}` : '';
|
|
719
832
|
}
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
833
|
+
}
|
|
834
|
+
byIndex(index) {
|
|
835
|
+
return index;
|
|
836
|
+
}
|
|
837
|
+
press(event) {
|
|
838
|
+
event.stopPropagation();
|
|
839
|
+
this.props['onPress']?.(event);
|
|
840
|
+
}
|
|
841
|
+
layout(event) {
|
|
842
|
+
this.props['onLayout']?.(event);
|
|
843
|
+
}
|
|
844
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.34", ngImport: i0, type: SsNodeComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
845
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.34", type: SsNodeComponent, isStandalone: true, selector: "ss-node", inputs: { node: "node", ctx: "ctx" }, usesOnChanges: true, ngImport: i0, template: `
|
|
846
|
+
<ng-container *ngIf="visible" [ngSwitch]="kind">
|
|
847
|
+
<ng-container *ngSwitchCase="'slot'">
|
|
848
|
+
<ss-node *ngIf="slot?.schema" [node]="slot!.schema!" [ctx]="slot!.context"></ss-node>
|
|
849
|
+
</ng-container>
|
|
850
|
+
<div *ngSwitchCase="'Box'" class="ss-node-box" [attr.data-ss-role]="role" [ngStyle]="css">
|
|
851
|
+
<ss-node *ngFor="let child of children; trackBy: byIndex" [node]="child" [ctx]="ctx"></ss-node>
|
|
731
852
|
</div>
|
|
732
|
-
<div
|
|
733
|
-
|
|
853
|
+
<div *ngSwitchCase="'Pressable'" class="ss-node-pressable" role="button" tabindex="0"
|
|
854
|
+
[attr.data-ss-role]="role" [attr.aria-label]="props['ariaLabel'] || null" [ngStyle]="css"
|
|
855
|
+
(click)="press($event)" (keydown.enter)="press($event)" (ssLayout)="layout($event)">
|
|
856
|
+
<ss-node *ngFor="let child of children; trackBy: byIndex" [node]="child" [ctx]="ctx"></ss-node>
|
|
734
857
|
</div>
|
|
735
|
-
|
|
858
|
+
<span *ngSwitchCase="'Text'" class="ss-node-text" [ngStyle]="css">{{ content }}</span>
|
|
859
|
+
<!-- A failed image keeps its space but shows nothing, like iOS and Flutter. -->
|
|
860
|
+
<img *ngSwitchCase="'Image'" class="ss-node-image" [attr.data-ss-role]="role" [src]="props['src']" [ngStyle]="css" alt=""
|
|
861
|
+
(error)="$any($event.target).style.visibility = 'hidden'" (load)="$any($event.target).style.visibility = ''" />
|
|
862
|
+
<img *ngSwitchCase="'SvgXml'" class="ss-node-svg" [src]="svgSrc" [ngStyle]="css" alt="" />
|
|
863
|
+
<ss-close-button *ngSwitchCase="'CloseButton'"></ss-close-button>
|
|
864
|
+
<ss-webview-renderer *ngSwitchCase="'WebViewRenderer'"
|
|
865
|
+
[attr.data-ss-webview]="node.meta?.['webViewType']"
|
|
866
|
+
[uri]="props['uri']" [canShow]="props['canShow']" [onMessage]="props['onMessage']"
|
|
867
|
+
[onError]="props['onError']" [refCallback]="props['ref']"></ss-webview-renderer>
|
|
868
|
+
</ng-container>
|
|
869
|
+
`, isInline: true, styles: ["ss-node,ss-close-button{display:contents}.ss-node-box,.ss-node-pressable,.ss-node-text,.ss-node-image,.ss-node-svg{box-sizing:border-box}.ss-node-pressable{-webkit-tap-highlight-color:transparent;user-select:none;-webkit-user-select:none}.ss-node-pressable:active{opacity:.6}.ss-node-pressable:focus{outline:none}\n"], dependencies: [{ kind: "component", type: i0.forwardRef(() => SsNodeComponent), selector: "ss-node", inputs: ["node", "ctx"] }, { kind: "directive", type: i0.forwardRef(() => NgIf), selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i0.forwardRef(() => NgFor), selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i0.forwardRef(() => NgStyle), selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "directive", type: i0.forwardRef(() => NgSwitch), selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i0.forwardRef(() => NgSwitchCase), selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "directive", type: i0.forwardRef(() => LayoutDirective), selector: "[ssLayout]", outputs: ["ssLayout"] }, { kind: "component", type: i0.forwardRef(() => WebViewRendererComponent), selector: "ss-webview-renderer", inputs: ["uri", "canShow", "onMessage", "onError", "refCallback"] }, { kind: "component", type: i0.forwardRef(() => CloseButtonComponent), selector: "ss-close-button" }], encapsulation: i0.ViewEncapsulation.None });
|
|
736
870
|
}
|
|
737
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.
|
|
871
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.34", ngImport: i0, type: SsNodeComponent, decorators: [{
|
|
738
872
|
type: Component,
|
|
739
|
-
args: [{
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
873
|
+
args: [{ selector: 'ss-node', standalone: true, encapsulation: ViewEncapsulation.None, imports: [
|
|
874
|
+
NgIf, NgFor, NgStyle, NgSwitch, NgSwitchCase, LayoutDirective, WebViewRendererComponent,
|
|
875
|
+
forwardRef(() => CloseButtonComponent),
|
|
876
|
+
], template: `
|
|
877
|
+
<ng-container *ngIf="visible" [ngSwitch]="kind">
|
|
878
|
+
<ng-container *ngSwitchCase="'slot'">
|
|
879
|
+
<ss-node *ngIf="slot?.schema" [node]="slot!.schema!" [ctx]="slot!.context"></ss-node>
|
|
880
|
+
</ng-container>
|
|
881
|
+
<div *ngSwitchCase="'Box'" class="ss-node-box" [attr.data-ss-role]="role" [ngStyle]="css">
|
|
882
|
+
<ss-node *ngFor="let child of children; trackBy: byIndex" [node]="child" [ctx]="ctx"></ss-node>
|
|
744
883
|
</div>
|
|
745
|
-
<div
|
|
746
|
-
|
|
884
|
+
<div *ngSwitchCase="'Pressable'" class="ss-node-pressable" role="button" tabindex="0"
|
|
885
|
+
[attr.data-ss-role]="role" [attr.aria-label]="props['ariaLabel'] || null" [ngStyle]="css"
|
|
886
|
+
(click)="press($event)" (keydown.enter)="press($event)" (ssLayout)="layout($event)">
|
|
887
|
+
<ss-node *ngFor="let child of children; trackBy: byIndex" [node]="child" [ctx]="ctx"></ss-node>
|
|
747
888
|
</div>
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
889
|
+
<span *ngSwitchCase="'Text'" class="ss-node-text" [ngStyle]="css">{{ content }}</span>
|
|
890
|
+
<!-- A failed image keeps its space but shows nothing, like iOS and Flutter. -->
|
|
891
|
+
<img *ngSwitchCase="'Image'" class="ss-node-image" [attr.data-ss-role]="role" [src]="props['src']" [ngStyle]="css" alt=""
|
|
892
|
+
(error)="$any($event.target).style.visibility = 'hidden'" (load)="$any($event.target).style.visibility = ''" />
|
|
893
|
+
<img *ngSwitchCase="'SvgXml'" class="ss-node-svg" [src]="svgSrc" [ngStyle]="css" alt="" />
|
|
894
|
+
<ss-close-button *ngSwitchCase="'CloseButton'"></ss-close-button>
|
|
895
|
+
<ss-webview-renderer *ngSwitchCase="'WebViewRenderer'"
|
|
896
|
+
[attr.data-ss-webview]="node.meta?.['webViewType']"
|
|
897
|
+
[uri]="props['uri']" [canShow]="props['canShow']" [onMessage]="props['onMessage']"
|
|
898
|
+
[onError]="props['onError']" [refCallback]="props['ref']"></ss-webview-renderer>
|
|
899
|
+
</ng-container>
|
|
900
|
+
`, styles: ["ss-node,ss-close-button{display:contents}.ss-node-box,.ss-node-pressable,.ss-node-text,.ss-node-image,.ss-node-svg{box-sizing:border-box}.ss-node-pressable{-webkit-tap-highlight-color:transparent;user-select:none;-webkit-user-select:none}.ss-node-pressable:active{opacity:.6}.ss-node-pressable:focus{outline:none}\n"] }]
|
|
901
|
+
}], propDecorators: { node: [{
|
|
753
902
|
type: Input
|
|
754
|
-
}],
|
|
903
|
+
}], ctx: [{
|
|
755
904
|
type: Input
|
|
756
905
|
}] } });
|
|
757
|
-
|
|
758
|
-
|
|
906
|
+
// Backend-driven close button (schema closeButton + closeButton.getCloseButtonStyles).
|
|
907
|
+
class CloseButtonComponent {
|
|
759
908
|
cdr;
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
909
|
+
schema = null;
|
|
910
|
+
ctx = {};
|
|
911
|
+
styles = {};
|
|
912
|
+
styleKey = [];
|
|
913
|
+
unsubscribers = [];
|
|
914
|
+
handlers = {
|
|
915
|
+
handleClosePress: () => {
|
|
916
|
+
execute('closeButton.handleCloseButton');
|
|
917
|
+
},
|
|
918
|
+
};
|
|
919
|
+
destroyed = false;
|
|
920
|
+
scheduleRender = batched(() => {
|
|
921
|
+
if (this.destroyed)
|
|
922
|
+
return;
|
|
923
|
+
this.ctx = { state: spotcheckStore.getState().SpotCheckState, styles: this.styles, handlers: this.handlers };
|
|
924
|
+
guardedDetectChanges(this.cdr, 'closeButtonRender');
|
|
925
|
+
});
|
|
926
|
+
constructor(cdr) {
|
|
767
927
|
this.cdr = cdr;
|
|
768
|
-
this.spotcheckStateService = getSpotcheckStateService();
|
|
769
|
-
this.state = this.spotcheckStateService.getState();
|
|
770
|
-
this.updateComponentStyles();
|
|
771
928
|
}
|
|
772
929
|
ngOnInit() {
|
|
773
|
-
this.
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
this.updateComponentStyles();
|
|
777
|
-
this.avatarUrl = this.state.avatarUrl || "https://static.surveysparrow.com/application/images/profile.png";
|
|
778
|
-
this.cdr.detectChanges();
|
|
779
|
-
});
|
|
780
|
-
});
|
|
781
|
-
this.initializeComponent();
|
|
930
|
+
this.unsubscribers.push(spotcheckStore.subscribe(() => this.update()));
|
|
931
|
+
this.unsubscribers.push(componentStore.subscribe(() => this.update()));
|
|
932
|
+
this.update();
|
|
782
933
|
}
|
|
783
934
|
ngOnDestroy() {
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
|
-
updateComponentStyles() {
|
|
789
|
-
this.componentStyles = getSpotcheckComponentCssStyles(this.state);
|
|
935
|
+
this.destroyed = true;
|
|
936
|
+
this.unsubscribers.forEach((unsubscribe) => unsubscribe());
|
|
790
937
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
}
|
|
805
|
-
else {
|
|
806
|
-
classicIframe = true;
|
|
807
|
-
}
|
|
808
|
-
});
|
|
809
|
-
const newClassicUrl = classicIframe
|
|
810
|
-
? `https://${domainName}/eui-template/classic`
|
|
811
|
-
: '';
|
|
812
|
-
const newChatUrl = chatIframe
|
|
813
|
-
? `https://${domainName}/eui-template/chat`
|
|
814
|
-
: '';
|
|
815
|
-
this.spotcheckStateService.setState({
|
|
816
|
-
filteredSpotChecks: data.filteredSpotChecks,
|
|
817
|
-
classicUrl: newClassicUrl,
|
|
818
|
-
chatUrl: newChatUrl,
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
catch (error) {
|
|
823
|
-
console.log('Error initializing widget:', JSON.stringify(error));
|
|
938
|
+
update() {
|
|
939
|
+
const state = spotcheckStore.getState().SpotCheckState;
|
|
940
|
+
const componentState = componentStore.getState().componentState;
|
|
941
|
+
this.schema = componentState.isLoaded ? componentState.schemas?.closeButton || null : null;
|
|
942
|
+
const key = [state.spotCheckDetails.closeButton, state.spotCheckDetails.isRTLLanguage];
|
|
943
|
+
if (key[0] !== this.styleKey[0] || key[1] !== this.styleKey[1]) {
|
|
944
|
+
this.styleKey = key;
|
|
945
|
+
execute('closeButton.getCloseButtonStyles').then((result) => {
|
|
946
|
+
if (!result)
|
|
947
|
+
return;
|
|
948
|
+
this.styles = result;
|
|
949
|
+
this.scheduleRender();
|
|
950
|
+
});
|
|
824
951
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
static
|
|
828
|
-
}
|
|
829
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.3", ngImport: i0, type: SpotCheckComponent, decorators: [{
|
|
830
|
-
type: Component,
|
|
831
|
-
args: [{ selector: 'SpotCheckComponent', standalone: true, imports: [CommonModule, WebViewComponent, CloseButtonComponent], template: "<div [ngStyle]=\"componentStyles.wrapperStyles\" class=\"safe-area\">\n <div [ngStyle]=\"componentStyles.styles\">\n <div style=\"position: relative; height: 100%;\">\n <spotcheck-close-button />\n \n <WebViewComponent\n *ngIf=\"state.classicUrl && state.classicUrl.length > 0 && state.spotcheckURL.length > 0 && state.spotCheckType === 'classic'\"\n [url]=\"state.classicUrl\"\n [webviewType]=\"'classic'\"\n [isMiniCard]=\"state.spotChecksMode === 'miniCard'\"\n />\n \n <WebViewComponent\n *ngIf=\"state.chatUrl && state.chatUrl.length > 0 && state.spotcheckURL.length > 0 && state.spotCheckType === 'chat'\"\n [url]=\"state.chatUrl\"\n [webviewType]=\"'chat'\"\n [isMiniCard]=\"state.spotChecksMode === 'miniCard'\"\n />\n\n <div *ngIf=\"state.spotChecksMode === 'miniCard' && state.avatarEnabled\">\n <div style=\"position: absolute; bottom: -66px; left: 16px; z-index: 100001;\">\n <img [src]=\"avatarUrl\" style=\"width: 56px; height: 56px; border-radius: 50px; background-color: white;\"/>\n </div>\n </div>\n </div>\n </div>\n</div>\n", styles: [".safe-area{padding-top:env(safe-area-inset-top);padding-bottom:env(safe-area-inset-bottom);padding-left:env(safe-area-inset-left);padding-right:env(safe-area-inset-right);box-sizing:border-box}\n"] }]
|
|
832
|
-
}], ctorParameters: () => [{ type: i0.NgZone }, { type: i0.ChangeDetectorRef }] });
|
|
833
|
-
|
|
834
|
-
class SpotCheck {
|
|
835
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.3", ngImport: i0, type: SpotCheck, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
836
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.3", type: SpotCheck, isStandalone: true, selector: "SpotCheck", ngImport: i0, template: `<SpotCheckComponent />`, isInline: true, dependencies: [{ kind: "component", type: SpotCheckComponent, selector: "SpotCheckComponent" }] });
|
|
952
|
+
this.scheduleRender();
|
|
953
|
+
}
|
|
954
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.34", ngImport: i0, type: CloseButtonComponent, deps: [{ token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
955
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.34", type: CloseButtonComponent, isStandalone: true, selector: "ss-close-button", ngImport: i0, template: `<ss-node *ngIf="schema" [node]="schema" [ctx]="ctx"></ss-node>`, isInline: true, dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: SsNodeComponent, selector: "ss-node", inputs: ["node", "ctx"] }] });
|
|
837
956
|
}
|
|
838
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.
|
|
957
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.34", ngImport: i0, type: CloseButtonComponent, decorators: [{
|
|
839
958
|
type: Component,
|
|
840
959
|
args: [{
|
|
841
|
-
selector: '
|
|
842
|
-
template: `<SpotCheckComponent />`,
|
|
960
|
+
selector: 'ss-close-button',
|
|
843
961
|
standalone: true,
|
|
844
|
-
imports: [
|
|
962
|
+
imports: [NgIf, SsNodeComponent],
|
|
963
|
+
template: `<ss-node *ngIf="schema" [node]="schema" [ctx]="ctx"></ss-node>`,
|
|
845
964
|
}]
|
|
846
|
-
}] });
|
|
965
|
+
}], ctorParameters: () => [{ type: i0.ChangeDetectorRef }] });
|
|
847
966
|
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
967
|
+
// Path only: query or hash changes stay on the same screen.
|
|
968
|
+
const pathOf = (url) => (url || '').split(/[?#]/)[0];
|
|
969
|
+
// Only one <SpotCheck> renders; extra instances stay empty so they never touch the live page.
|
|
970
|
+
let owner = null;
|
|
971
|
+
// Keyboard cover below this is browser chrome, not a keyboard.
|
|
972
|
+
const MIN_KEYBOARD_HEIGHT = 80;
|
|
973
|
+
// Place once at the app root: <SpotCheck />. One Angular codebase for web, Android and iOS.
|
|
974
|
+
class SpotCheck {
|
|
975
|
+
wrapperSchema = null;
|
|
976
|
+
buttonSchema = null;
|
|
977
|
+
wrapperCtx = {};
|
|
978
|
+
buttonCtx = {};
|
|
979
|
+
buttonReady = false;
|
|
980
|
+
wrapperStyles = {
|
|
981
|
+
overlayStyle: { position: 'fixed', height: 0, opacity: 0, zIndex: -999999, pointerEvents: 'none' },
|
|
982
|
+
wrapperStyle: {},
|
|
983
|
+
};
|
|
984
|
+
buttonStyles = {};
|
|
985
|
+
destroyed = false;
|
|
986
|
+
cleanups = [];
|
|
987
|
+
lastInjectionKey = [];
|
|
988
|
+
lastButtonKey = [];
|
|
989
|
+
lastPath = null;
|
|
990
|
+
cdr = inject(ChangeDetectorRef);
|
|
991
|
+
zone = inject(NgZone);
|
|
992
|
+
router = inject(Router, { optional: true });
|
|
993
|
+
isBrowser = isPlatformBrowser(inject(PLATFORM_ID));
|
|
994
|
+
webviewHandlers = {
|
|
995
|
+
classicWebViewRefCallback: (ref) => execute('webviewComponent.classicWebViewRefCallback', { ref }),
|
|
996
|
+
chatWebViewRefCallback: (ref) => execute('webviewComponent.chatWebViewRefCallback', { ref }),
|
|
997
|
+
handleOnMessage: (event) => execute('webviewComponent.handleWebViewMessage', { event }),
|
|
998
|
+
handleOnError: (error) => execute('webviewComponent.handleWebViewError', { error }),
|
|
999
|
+
};
|
|
1000
|
+
buttonHandlers = {
|
|
1001
|
+
handleSpotCheckButtonPress: () => execute('spotCheckButton.handleSpotCheckButtonPress'),
|
|
1002
|
+
handleSideTabLayout: (event) => execute('spotCheckButton.handleSideTabLayout', { event }),
|
|
1003
|
+
};
|
|
1004
|
+
scheduleRender = batched(() => {
|
|
1005
|
+
if (!this.destroyed)
|
|
1006
|
+
this.render();
|
|
1007
|
+
});
|
|
1008
|
+
scheduleWrapperStyles = batched(() => {
|
|
1009
|
+
if (this.destroyed)
|
|
1010
|
+
return;
|
|
1011
|
+
execute('wrapper.getWrapperStyles', {
|
|
1012
|
+
screenHeight: window.innerHeight,
|
|
1013
|
+
screenWidth: window.innerWidth,
|
|
1014
|
+
setStyles: (styles) => {
|
|
1015
|
+
this.wrapperStyles = styles;
|
|
1016
|
+
this.scheduleRender();
|
|
885
1017
|
},
|
|
886
1018
|
});
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
1019
|
+
});
|
|
1020
|
+
ngOnInit() {
|
|
1021
|
+
// Server render (SSR) or a second instance: render nothing.
|
|
1022
|
+
if (!this.isBrowser || owner)
|
|
1023
|
+
return;
|
|
1024
|
+
owner = this;
|
|
1025
|
+
// App callbacks run inside Angular so the app's own UI updates.
|
|
1026
|
+
setAppRunner((fn) => this.zone.run(fn));
|
|
1027
|
+
this.cleanups.push(spotcheckStore.subscribe(() => this.onStateChange()));
|
|
1028
|
+
this.cleanups.push(componentStore.subscribe(() => this.onStateChange()));
|
|
1029
|
+
this.cleanups.push(onCrash(() => this.hideAfterCrash()));
|
|
1030
|
+
this.watchWindow();
|
|
1031
|
+
this.watchRouter();
|
|
1032
|
+
this.onStateChange();
|
|
1033
|
+
}
|
|
1034
|
+
ngOnDestroy() {
|
|
1035
|
+
if (owner === this)
|
|
1036
|
+
owner = null;
|
|
1037
|
+
this.destroyed = true;
|
|
1038
|
+
this.cleanups.forEach((cleanup) => cleanup());
|
|
1039
|
+
}
|
|
1040
|
+
// Same triggers as the other SDKs' Wrapper / WebViewComponent / SpotCheckButton effects.
|
|
1041
|
+
onStateChange() {
|
|
1042
|
+
const state = spotcheckStore.getState().SpotCheckState;
|
|
1043
|
+
const { webViewDetails, spotCheckDetails } = state;
|
|
1044
|
+
this.scheduleWrapperStyles();
|
|
1045
|
+
const injectionKey = [webViewDetails.isChatLoading, webViewDetails.isClassicLoading, webViewDetails.webViewInjectionData];
|
|
1046
|
+
if (injectionKey.some((value, i) => value !== this.lastInjectionKey[i])) {
|
|
1047
|
+
this.lastInjectionKey = injectionKey;
|
|
1048
|
+
execute('webviewComponent.handleWebViewInjection');
|
|
1049
|
+
}
|
|
1050
|
+
const buttonKey = [spotCheckDetails.spotCheckButtonConfig, spotCheckDetails.isSpotCheckButton, spotCheckDetails.sideTabButtonWidth];
|
|
1051
|
+
if (buttonKey.some((value, i) => value !== this.lastButtonKey[i])) {
|
|
1052
|
+
this.lastButtonKey = buttonKey;
|
|
1053
|
+
execute('spotCheckButton.getSpotCheckButtonStyles').then((result) => {
|
|
1054
|
+
if (!result)
|
|
1055
|
+
return;
|
|
1056
|
+
this.buttonStyles = result;
|
|
1057
|
+
this.scheduleRender();
|
|
1058
|
+
});
|
|
1059
|
+
}
|
|
1060
|
+
this.scheduleRender();
|
|
1061
|
+
}
|
|
1062
|
+
render() {
|
|
1063
|
+
if (hasCrashed())
|
|
1064
|
+
return;
|
|
1065
|
+
const state = spotcheckStore.getState().SpotCheckState;
|
|
1066
|
+
const componentState = componentStore.getState().componentState;
|
|
1067
|
+
const schemas = componentState.isLoaded ? componentState.schemas || {} : {};
|
|
1068
|
+
this.wrapperSchema = schemas.wrapper || null;
|
|
1069
|
+
this.buttonSchema = schemas.spotCheckButton || null;
|
|
1070
|
+
this.wrapperCtx = {
|
|
1071
|
+
state,
|
|
1072
|
+
styles: this.wrapperStyles,
|
|
1073
|
+
slots: {
|
|
1074
|
+
children: {
|
|
1075
|
+
schema: schemas.webviewComponent || null,
|
|
1076
|
+
context: { state, handlers: this.webviewHandlers },
|
|
899
1077
|
},
|
|
900
|
-
currentDate: new Date().toISOString(),
|
|
901
|
-
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
902
1078
|
},
|
|
903
|
-
traceId: state.traceId,
|
|
904
|
-
customProperties: customProperties,
|
|
905
1079
|
};
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
1080
|
+
this.buttonCtx = { state, styles: this.buttonStyles, handlers: this.buttonHandlers };
|
|
1081
|
+
// Wait for styles so the button never renders unstyled for a frame.
|
|
1082
|
+
this.buttonReady = Object.keys(this.buttonStyles || {}).length > 0;
|
|
1083
|
+
guardedDetectChanges(this.cdr, 'render');
|
|
1084
|
+
}
|
|
1085
|
+
// After a failed draw, SpotCheck renders nothing for the rest of the session (RN error boundary parity).
|
|
1086
|
+
hideAfterCrash() {
|
|
1087
|
+
this.wrapperSchema = null;
|
|
1088
|
+
this.buttonSchema = null;
|
|
1089
|
+
try {
|
|
1090
|
+
this.cdr.detectChanges();
|
|
1091
|
+
}
|
|
1092
|
+
catch { }
|
|
1093
|
+
}
|
|
1094
|
+
// Screen size and the part of it the on-screen keyboard covers.
|
|
1095
|
+
watchWindow() {
|
|
1096
|
+
const vv = window.visualViewport;
|
|
1097
|
+
const onResize = () => {
|
|
1098
|
+
let keyboard = 0;
|
|
1099
|
+
if (vv)
|
|
1100
|
+
keyboard = Math.round(window.innerHeight - vv.height - vv.offsetTop);
|
|
1101
|
+
if (keyboard < MIN_KEYBOARD_HEIGHT)
|
|
1102
|
+
keyboard = 0;
|
|
1103
|
+
const current = spotcheckStore.getState().SpotCheckState.spotCheckDetails.keyBoardHeight || 0;
|
|
1104
|
+
if (keyboard !== current)
|
|
1105
|
+
dispatchWrapper({ spotCheckDetails: { keyBoardHeight: keyboard } });
|
|
1106
|
+
else
|
|
1107
|
+
this.scheduleWrapperStyles();
|
|
1108
|
+
};
|
|
1109
|
+
this.zone.runOutsideAngular(() => {
|
|
1110
|
+
window.addEventListener('resize', onResize);
|
|
1111
|
+
vv?.addEventListener('resize', onResize);
|
|
1112
|
+
vv?.addEventListener('scroll', onResize);
|
|
911
1113
|
});
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
if (!isSpotPassed && responseJson?.checkPassed) {
|
|
931
|
-
if (responseJson.checkCondition) {
|
|
932
|
-
const checkCondition = responseJson.checkCondition;
|
|
933
|
-
spotcheckStateService.setState({ afterDelay: checkCondition.afterDelay || 0 });
|
|
934
|
-
if (checkCondition.customEvent) {
|
|
935
|
-
spotcheckStateService.setState({ customEventsSpotChecks: [responseJson] });
|
|
936
|
-
throw new Error('');
|
|
1114
|
+
this.cleanups.push(() => {
|
|
1115
|
+
window.removeEventListener('resize', onResize);
|
|
1116
|
+
vv?.removeEventListener('resize', onResize);
|
|
1117
|
+
vv?.removeEventListener('scroll', onResize);
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
// Leaving a screen closes its spotcheck. GuardsCheckEnd comes after guards and redirects
|
|
1121
|
+
// (a blocked navigation keeps the survey) and before the new page's trackScreen.
|
|
1122
|
+
watchRouter() {
|
|
1123
|
+
if (!this.router)
|
|
1124
|
+
return;
|
|
1125
|
+
this.lastPath = this.router.navigated ? pathOf(this.router.url) : null;
|
|
1126
|
+
const subscription = this.router.events.subscribe((event) => {
|
|
1127
|
+
try {
|
|
1128
|
+
if (event instanceof GuardsCheckEnd && event.shouldActivate) {
|
|
1129
|
+
const next = pathOf(event.urlAfterRedirects);
|
|
1130
|
+
if (this.lastPath !== null && next !== this.lastPath) {
|
|
1131
|
+
execute('handleNavigationChange');
|
|
937
1132
|
}
|
|
1133
|
+
this.lastPath = next;
|
|
938
1134
|
}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
isChecksPassed = true;
|
|
942
|
-
spotcheckStateService.setState({ isChecksPassed });
|
|
943
|
-
return { valid: true };
|
|
1135
|
+
else if (event instanceof NavigationEnd) {
|
|
1136
|
+
this.lastPath = pathOf(event.urlAfterRedirects);
|
|
944
1137
|
}
|
|
945
1138
|
}
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
spotcheckStateService.setState({ customEventsSpotChecks: responseJson.resultantSpotCheck });
|
|
949
|
-
let selectedSpotCheck = {};
|
|
950
|
-
let minDelay = Number.POSITIVE_INFINITY;
|
|
951
|
-
for (const spotcheck of responseJson.resultantSpotCheck) {
|
|
952
|
-
const checks = spotcheck?.checks || {};
|
|
953
|
-
if (Object.keys(checks).length === 0) {
|
|
954
|
-
minDelay = 0;
|
|
955
|
-
selectedSpotCheck = spotcheck;
|
|
956
|
-
}
|
|
957
|
-
else if (checks.afterDelay != null) {
|
|
958
|
-
const delay = parseFloat(checks.afterDelay);
|
|
959
|
-
if (minDelay > delay) {
|
|
960
|
-
minDelay = delay;
|
|
961
|
-
selectedSpotCheck = spotcheck;
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
}
|
|
965
|
-
if (Object.keys(selectedSpotCheck).length > 0) {
|
|
966
|
-
spotcheckStateService.setState({ afterDelay: minDelay });
|
|
967
|
-
const appearance_response = await setAppearance(selectedSpotCheck, screen, state.domainName, traceId, variables);
|
|
968
|
-
if (appearance_response) {
|
|
969
|
-
return { valid: true };
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
}
|
|
1139
|
+
catch (error) {
|
|
1140
|
+
captureP1Error(error, 'GENERAL', { action: 'navigationListener', errorMessage: error?.message });
|
|
973
1141
|
}
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
else {
|
|
977
|
-
throw new Error(`Received status code ${response.status}`);
|
|
978
|
-
}
|
|
1142
|
+
});
|
|
1143
|
+
this.cleanups.push(() => subscription.unsubscribe());
|
|
979
1144
|
}
|
|
980
|
-
|
|
981
|
-
|
|
1145
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.3.34", ngImport: i0, type: SpotCheck, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
1146
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "20.3.34", type: SpotCheck, isStandalone: true, selector: "SpotCheck", ngImport: i0, template: `
|
|
1147
|
+
<ss-node *ngIf="wrapperSchema" [node]="wrapperSchema" [ctx]="wrapperCtx"></ss-node>
|
|
1148
|
+
<ss-node *ngIf="buttonSchema && buttonReady" [node]="buttonSchema" [ctx]="buttonCtx"></ss-node>
|
|
1149
|
+
`, isInline: true, styles: [":host{display:contents}\n"], dependencies: [{ kind: "directive", type: NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "component", type: SsNodeComponent, selector: "ss-node", inputs: ["node", "ctx"] }] });
|
|
1150
|
+
}
|
|
1151
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.34", ngImport: i0, type: SpotCheck, decorators: [{
|
|
1152
|
+
type: Component,
|
|
1153
|
+
args: [{ selector: 'SpotCheck', standalone: true, imports: [NgIf, SsNodeComponent], template: `
|
|
1154
|
+
<ss-node *ngIf="wrapperSchema" [node]="wrapperSchema" [ctx]="wrapperCtx"></ss-node>
|
|
1155
|
+
<ss-node *ngIf="buttonSchema && buttonReady" [node]="buttonSchema" [ctx]="buttonCtx"></ss-node>
|
|
1156
|
+
`, styles: [":host{display:contents}\n"] }]
|
|
1157
|
+
}] });
|
|
1158
|
+
|
|
1159
|
+
let deviceInfo = null;
|
|
1160
|
+
const getDeviceInfo = async () => {
|
|
1161
|
+
if (deviceInfo)
|
|
1162
|
+
return deviceInfo;
|
|
1163
|
+
try {
|
|
1164
|
+
deviceInfo = await Device.getInfo();
|
|
1165
|
+
}
|
|
1166
|
+
catch {
|
|
1167
|
+
deviceInfo = { platform: Capacitor.getPlatform(), operatingSystem: 'unknown', osVersion: '' };
|
|
982
1168
|
}
|
|
1169
|
+
return deviceInfo;
|
|
983
1170
|
};
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
customEvent: event,
|
|
1017
|
-
},
|
|
1018
|
-
traceId: state.traceId,
|
|
1019
|
-
customProperties: state.customProperties,
|
|
1020
|
-
};
|
|
1021
|
-
const url = `https://${state.domainName}/api/internal/spotcheck/widget/${state.targetToken}/eventTrigger?isSpotCheck=true`;
|
|
1022
|
-
try {
|
|
1023
|
-
const response = await axios.post(url, payload, {
|
|
1024
|
-
headers: {
|
|
1025
|
-
'Content-Type': 'application/json',
|
|
1026
|
-
},
|
|
1027
|
-
});
|
|
1028
|
-
if (response.status === 200) {
|
|
1029
|
-
const responseJson = response.data;
|
|
1030
|
-
if (responseJson?.show != null) {
|
|
1031
|
-
if (responseJson?.show) {
|
|
1032
|
-
const appearance_response = await setAppearance(responseJson, screen, state.domainName, state.traceId, state.variables);
|
|
1033
|
-
if (appearance_response) {
|
|
1034
|
-
getSpotcheckStateService().setState({ isSpotPassed: true });
|
|
1035
|
-
isSpotPassed = true;
|
|
1036
|
-
return { valid: true };
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
if (!isSpotPassed && responseJson?.eventShow) {
|
|
1041
|
-
if (responseJson?.checkCondition != null) {
|
|
1042
|
-
const checkCondition = responseJson?.checkCondition;
|
|
1043
|
-
getSpotcheckStateService().setState({
|
|
1044
|
-
afterDelay: checkCondition?.afterDelay ?? 0,
|
|
1045
|
-
});
|
|
1046
|
-
if (checkCondition?.customEvent != null) {
|
|
1047
|
-
getSpotcheckStateService().setState({
|
|
1048
|
-
afterDelay: checkCondition?.customEvent?.delayInSeconds ?? 0,
|
|
1049
|
-
});
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
const appearance_response = await setAppearance(responseJson, screen, state.domainName, state.traceId, state.variables);
|
|
1053
|
-
if (appearance_response) {
|
|
1054
|
-
return { valid: true };
|
|
1055
|
-
}
|
|
1056
|
-
}
|
|
1057
|
-
throw new Error(responseJson?.reason?.toString() ?? 'Event conditions not met');
|
|
1058
|
-
}
|
|
1059
|
-
else {
|
|
1060
|
-
throw new Error(`Received status code ${response.status}`);
|
|
1061
|
-
}
|
|
1062
|
-
}
|
|
1063
|
-
catch (error) {
|
|
1064
|
-
throw new Error(error.message);
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
throw new Error('');
|
|
1171
|
+
// Legacy Ionic visitor: operatingSystem from @capacitor/device (cached at init), size from the window.
|
|
1172
|
+
const getVisitorInfo = () => {
|
|
1173
|
+
const info = deviceInfo || {};
|
|
1174
|
+
return {
|
|
1175
|
+
deviceType: 'MOBILE',
|
|
1176
|
+
operatingSystem: info.operatingSystem || 'unknown',
|
|
1177
|
+
screenResolution: {
|
|
1178
|
+
width: Math.round(window.innerWidth),
|
|
1179
|
+
height: Math.round(window.innerHeight),
|
|
1180
|
+
},
|
|
1181
|
+
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
|
|
1182
|
+
};
|
|
1183
|
+
};
|
|
1184
|
+
const loadDeviceInfo = () => getDeviceInfo();
|
|
1185
|
+
// Raw device facts; the backend keeps the SDK version per app build.
|
|
1186
|
+
const getDeviceFacts = async () => {
|
|
1187
|
+
const info = await getDeviceInfo();
|
|
1188
|
+
const facts = {
|
|
1189
|
+
os: info.platform === 'web' ? 'web' : info.platform,
|
|
1190
|
+
osVersion: String(info.osVersion || ''),
|
|
1191
|
+
isTablet: false,
|
|
1192
|
+
...(info.model ? { model: String(info.model) } : {}),
|
|
1193
|
+
};
|
|
1194
|
+
if (Capacitor.isNativePlatform()) {
|
|
1195
|
+
try {
|
|
1196
|
+
// @capacitor/app is optional; its native plugin registers here when installed.
|
|
1197
|
+
const app = Capacitor.Plugins?.App;
|
|
1198
|
+
const appInfo = app?.getInfo ? await app.getInfo() : null;
|
|
1199
|
+
if (appInfo?.version)
|
|
1200
|
+
facts['appVersion'] = String(appInfo.version);
|
|
1201
|
+
if (appInfo?.build)
|
|
1202
|
+
facts['appBuild'] = String(appInfo.build);
|
|
1071
1203
|
}
|
|
1072
|
-
|
|
1073
|
-
|
|
1204
|
+
catch { }
|
|
1205
|
+
}
|
|
1206
|
+
return facts;
|
|
1207
|
+
};
|
|
1208
|
+
|
|
1209
|
+
const INIT_TIMEOUT_MS = 15000;
|
|
1210
|
+
// Backend functions, schemas and page script for this SDK (framework=ionic).
|
|
1211
|
+
const getAllSpotcheckFunctions = async (domainName) => {
|
|
1212
|
+
const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;
|
|
1213
|
+
const timer = setTimeout(() => controller?.abort(), INIT_TIMEOUT_MS);
|
|
1214
|
+
try {
|
|
1215
|
+
const response = await fetch(`https://${domainName}/api/internal/spotcheck/mobile/init?framework=${FRAMEWORK}`, { signal: controller?.signal, cache: 'no-store' });
|
|
1216
|
+
if (!response.ok)
|
|
1217
|
+
throw new Error(`mobile/init failed with status ${response.status}`);
|
|
1218
|
+
const data = await response.json().catch(() => null);
|
|
1219
|
+
// A non-JSON 200 (e.g. captive portal) counts as a failed init.
|
|
1220
|
+
if (!data || typeof data !== 'object' || typeof data.initializeSpotcheckComponent !== 'string') {
|
|
1221
|
+
throw new Error('Invalid mobile/init response');
|
|
1074
1222
|
}
|
|
1223
|
+
const { componentSchemas, config, ...functions } = data;
|
|
1224
|
+
functionStore.dispatch({ ...functions, isLoaded: true });
|
|
1225
|
+
componentStore.dispatch({ schemas: componentSchemas || {}, config: config || {}, isLoaded: Boolean(componentSchemas) });
|
|
1226
|
+
return data;
|
|
1075
1227
|
}
|
|
1076
1228
|
catch (error) {
|
|
1077
|
-
|
|
1229
|
+
captureP0Error(error, 'SPOTCHECK_INITIALIZATION', {
|
|
1230
|
+
component: 'getAllSpotcheckFunctions',
|
|
1231
|
+
action: 'fetchFunctions',
|
|
1232
|
+
domainName,
|
|
1233
|
+
errorMessage: error?.message,
|
|
1234
|
+
});
|
|
1235
|
+
console.error('Error fetching spotcheck functions:', error);
|
|
1236
|
+
throw error;
|
|
1237
|
+
}
|
|
1238
|
+
finally {
|
|
1239
|
+
clearTimeout(timer);
|
|
1078
1240
|
}
|
|
1079
1241
|
};
|
|
1080
|
-
|
|
1081
|
-
const
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1242
|
+
// Synchronous: trackScreen must reach execute in the same tick as a following trackEvent.
|
|
1243
|
+
const refreshVisitor = () => {
|
|
1244
|
+
try {
|
|
1245
|
+
spotcheckStore.dispatch({ params: { visitor: getVisitorInfo() } });
|
|
1246
|
+
}
|
|
1247
|
+
catch { }
|
|
1248
|
+
};
|
|
1249
|
+
// Init retry: a failed init (e.g. offline at launch) is retried on the next track call.
|
|
1250
|
+
const INIT_RETRY_GAP_MS = 10000;
|
|
1251
|
+
let lastInitParams = null;
|
|
1252
|
+
let initStatus = 'idle';
|
|
1253
|
+
let lastInitAttempt = 0;
|
|
1254
|
+
const retryInitIfFailed = () => {
|
|
1255
|
+
if (initStatus !== 'failed' || !lastInitParams)
|
|
1256
|
+
return;
|
|
1257
|
+
if (Date.now() - lastInitAttempt < INIT_RETRY_GAP_MS)
|
|
1258
|
+
return;
|
|
1259
|
+
initializeSpotChecks(lastInitParams).catch(() => { });
|
|
1090
1260
|
};
|
|
1091
|
-
const
|
|
1261
|
+
const initializeSpotChecks = async (params) => {
|
|
1262
|
+
lastInitParams = params;
|
|
1263
|
+
initStatus = 'running';
|
|
1264
|
+
lastInitAttempt = Date.now();
|
|
1092
1265
|
try {
|
|
1093
|
-
|
|
1094
|
-
if (
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
}
|
|
1266
|
+
setListener(params?.listener);
|
|
1267
|
+
if (params?.domainName)
|
|
1268
|
+
spotcheckStore.dispatch({ params: { domainName: params.domainName } });
|
|
1269
|
+
await loadDeviceInfo();
|
|
1270
|
+
refreshVisitor();
|
|
1271
|
+
const device = await getDeviceFacts();
|
|
1272
|
+
await getAllSpotcheckFunctions(params.domainName);
|
|
1273
|
+
const { listener, ...initParams } = params;
|
|
1274
|
+
await execute('initializeSpotcheckComponent', { ...initParams, framework: FRAMEWORK, device });
|
|
1275
|
+
await markInitialized();
|
|
1276
|
+
initStatus = 'done';
|
|
1105
1277
|
}
|
|
1106
1278
|
catch (error) {
|
|
1107
|
-
|
|
1279
|
+
// Legacy never threw into the host app; failures go to the backend and the console.
|
|
1280
|
+
console.error('Error initializing spotchecks:', error);
|
|
1281
|
+
initStatus = 'failed';
|
|
1108
1282
|
}
|
|
1109
1283
|
};
|
|
1110
|
-
const
|
|
1284
|
+
const resolveTrackOptions = (input) => ({
|
|
1285
|
+
variables: input?.variables ?? {},
|
|
1286
|
+
customProperties: input?.customProperties ?? {},
|
|
1287
|
+
userDetails: input?.userDetails ?? {},
|
|
1288
|
+
});
|
|
1289
|
+
async function trackScreen(screenOrProps, optionsArg) {
|
|
1290
|
+
const screen = typeof screenOrProps === 'string' ? screenOrProps : screenOrProps?.screen;
|
|
1291
|
+
const options = resolveTrackOptions(typeof screenOrProps === 'string' ? optionsArg : screenOrProps?.options);
|
|
1292
|
+
if (!screen) {
|
|
1293
|
+
console.error('trackScreen: `screen` is required');
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
addBreadcrumb('trackScreen', { screen });
|
|
1297
|
+
retryInitIfFailed();
|
|
1111
1298
|
try {
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
console.log('TrackEvent succeeded.');
|
|
1115
|
-
}
|
|
1116
|
-
else {
|
|
1117
|
-
if ('error' in response) {
|
|
1118
|
-
throw new Error(response.error.toString());
|
|
1119
|
-
}
|
|
1120
|
-
else {
|
|
1121
|
-
throw new Error('Tracking failed without an explicit error.');
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1299
|
+
refreshVisitor();
|
|
1300
|
+
await execute('trackScreen', { screen, options });
|
|
1124
1301
|
}
|
|
1125
1302
|
catch (error) {
|
|
1126
|
-
|
|
1303
|
+
// Legacy only logged; never throw into the host app.
|
|
1304
|
+
console.error('Error tracking screen:', error);
|
|
1127
1305
|
}
|
|
1128
|
-
}
|
|
1306
|
+
}
|
|
1307
|
+
async function trackEvent(screenOrProps, eventArg, optionsArg) {
|
|
1308
|
+
const isString = typeof screenOrProps === 'string';
|
|
1309
|
+
const screen = isString ? screenOrProps : screenOrProps?.screen;
|
|
1310
|
+
const event = isString ? eventArg : screenOrProps?.event;
|
|
1311
|
+
if (!screen) {
|
|
1312
|
+
console.error('trackEvent: `screen` is required');
|
|
1313
|
+
return;
|
|
1314
|
+
}
|
|
1315
|
+
if (event == null) {
|
|
1316
|
+
console.error('trackEvent: `event` is required');
|
|
1317
|
+
return;
|
|
1318
|
+
}
|
|
1319
|
+
const options = resolveTrackOptions(isString ? optionsArg : screenOrProps.options);
|
|
1320
|
+
addBreadcrumb('trackEvent', { screen, event: Object.keys(event || {}).join(',') });
|
|
1321
|
+
retryInitIfFailed();
|
|
1322
|
+
try {
|
|
1323
|
+
await execute('trackEvent', { screen, event, options });
|
|
1324
|
+
}
|
|
1325
|
+
catch (error) {
|
|
1326
|
+
console.error('Error tracking event:', error);
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
// Closes any open spotcheck and its button (screen changes the SDK can't detect).
|
|
1330
|
+
async function closeSpotChecks() {
|
|
1331
|
+
addBreadcrumb('closeSpotChecks', {});
|
|
1332
|
+
await execute('handleNavigationChange', { reason: 'close' });
|
|
1333
|
+
}
|
|
1129
1334
|
|
|
1130
1335
|
/**
|
|
1131
1336
|
* Generated bundle index. Do not edit.
|
|
1132
1337
|
*/
|
|
1133
1338
|
|
|
1134
|
-
export { SpotCheck, addSpotCheckListener, initializeSpotChecks, trackEvent, trackScreen };
|
|
1339
|
+
export { SDK_VERSION, SpotCheck, addSpotCheckListener, closeSpotChecks, initializeSpotChecks, trackEvent, trackScreen };
|
|
1135
1340
|
//# sourceMappingURL=angular-ui.mjs.map
|