surveysparrow-ionic-plugin 2.0.3 → 2.0.4-beta.1
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
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// SDK errors go to SurveySparrow's API (backend sentry.processSentryError), never to Sentry servers.
|
|
2
|
+
import { spotcheckStore } from '../state/store';
|
|
3
|
+
import { SDK_VERSION, FRAMEWORK } from './version';
|
|
4
|
+
// Set by executables.ts at load time (avoids a circular import).
|
|
5
|
+
let executeRef = null;
|
|
6
|
+
export const registerExecute = (fn) => {
|
|
7
|
+
executeRef = fn;
|
|
8
|
+
};
|
|
9
|
+
const MAX_BREADCRUMBS = 30;
|
|
10
|
+
const sdkBreadcrumbs = [];
|
|
11
|
+
export const addBreadcrumb = (message, data) => {
|
|
12
|
+
sdkBreadcrumbs.push({ category: 'spotcheck', message, data, timestamp: Date.now() / 1000 });
|
|
13
|
+
if (sdkBreadcrumbs.length > MAX_BREADCRUMBS)
|
|
14
|
+
sdkBreadcrumbs.shift();
|
|
15
|
+
};
|
|
16
|
+
const MAX_BREADCRUMB_STRING = 200;
|
|
17
|
+
const capString = (value) => value.slice(0, MAX_BREADCRUMB_STRING);
|
|
18
|
+
// Breadcrumb hook for backend functions; drops bad input and never throws.
|
|
19
|
+
export const safeAddBreadcrumb = (message, data) => {
|
|
20
|
+
try {
|
|
21
|
+
if (typeof message !== 'string')
|
|
22
|
+
return;
|
|
23
|
+
let clean;
|
|
24
|
+
const proto = data && typeof data === 'object' ? Object.getPrototypeOf(data) : undefined;
|
|
25
|
+
if (proto === Object.prototype || proto === null) {
|
|
26
|
+
clean = {};
|
|
27
|
+
Object.keys(data).forEach((key) => {
|
|
28
|
+
const value = data[key];
|
|
29
|
+
if (typeof value === 'string')
|
|
30
|
+
clean[key] = capString(value);
|
|
31
|
+
else if (value === null || typeof value === 'number' || typeof value === 'boolean')
|
|
32
|
+
clean[key] = value;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
addBreadcrumb(capString(message), clean);
|
|
36
|
+
}
|
|
37
|
+
catch (_a) { }
|
|
38
|
+
};
|
|
39
|
+
// Flags an error as reported so execute() does not report it again.
|
|
40
|
+
const markReported = (error) => {
|
|
41
|
+
try {
|
|
42
|
+
if (error !== null && typeof error === 'object') {
|
|
43
|
+
Object.defineProperty(error, '__ssReported', { value: true, configurable: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (_a) { }
|
|
47
|
+
};
|
|
48
|
+
export const isReported = (error) => {
|
|
49
|
+
try {
|
|
50
|
+
return !!(error === null || error === void 0 ? void 0 : error.__ssReported);
|
|
51
|
+
}
|
|
52
|
+
catch (_a) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
// Routes an event to the backend; never throws.
|
|
57
|
+
const sendToBackend = async (normalizedEvent) => {
|
|
58
|
+
var _a, _b;
|
|
59
|
+
try {
|
|
60
|
+
const result = executeRef
|
|
61
|
+
? await executeRef('sentry.processSentryError', {
|
|
62
|
+
event: normalizedEvent,
|
|
63
|
+
sdkType: FRAMEWORK,
|
|
64
|
+
sdkVersion: SDK_VERSION,
|
|
65
|
+
})
|
|
66
|
+
: null;
|
|
67
|
+
if (result)
|
|
68
|
+
return;
|
|
69
|
+
const { domainName, targetToken } = ((_a = spotcheckStore.getState().SpotCheckState) === null || _a === void 0 ? void 0 : _a.params) || {};
|
|
70
|
+
if (!domainName)
|
|
71
|
+
return;
|
|
72
|
+
await fetch(`https://${domainName}/api/internal/spotcheck/sdkErrors`, {
|
|
73
|
+
method: 'POST',
|
|
74
|
+
headers: { 'Content-Type': 'application/json' },
|
|
75
|
+
body: JSON.stringify({
|
|
76
|
+
errorMessage: normalizedEvent.errorMessage,
|
|
77
|
+
sdkType: FRAMEWORK,
|
|
78
|
+
sdkVersion: SDK_VERSION,
|
|
79
|
+
level: ((_b = normalizedEvent.tags) === null || _b === void 0 ? void 0 : _b.error_priority) === 'P0' ? 'fatal' : 'error',
|
|
80
|
+
tags: normalizedEvent.tags,
|
|
81
|
+
extra: normalizedEvent.extra,
|
|
82
|
+
breadcrumbs: normalizedEvent.breadcrumbs,
|
|
83
|
+
contexts: { user: { spotcheck_token: targetToken || '', spotcheck_domain_name: domainName } },
|
|
84
|
+
}),
|
|
85
|
+
}).catch(() => { });
|
|
86
|
+
}
|
|
87
|
+
catch (_c) {
|
|
88
|
+
// Reporting must never break the host app.
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
const report = (error, priority, source, extra) => {
|
|
92
|
+
markReported(error);
|
|
93
|
+
const err = error;
|
|
94
|
+
sendToBackend({
|
|
95
|
+
errorMessage: (err === null || err === void 0 ? void 0 : err.message) || String(error),
|
|
96
|
+
tags: {
|
|
97
|
+
error_priority: priority,
|
|
98
|
+
severity: priority === 'P0' ? 'CRITICAL' : 'HIGH',
|
|
99
|
+
errorType: source,
|
|
100
|
+
},
|
|
101
|
+
contexts: {},
|
|
102
|
+
extra: extra || {},
|
|
103
|
+
breadcrumbs: [...sdkBreadcrumbs],
|
|
104
|
+
exceptions: [{
|
|
105
|
+
type: (err === null || err === void 0 ? void 0 : err.name) || 'Error',
|
|
106
|
+
value: (err === null || err === void 0 ? void 0 : err.message) || String(error),
|
|
107
|
+
stack: String((err === null || err === void 0 ? void 0 : err.stack) || '').slice(0, 2000),
|
|
108
|
+
}],
|
|
109
|
+
timestamp: Date.now() / 1000,
|
|
110
|
+
platform: 'javascript',
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
export const captureP0Error = (error, source, extra) => report(error, 'P0', source, extra);
|
|
114
|
+
export const captureP1Error = (error, source, extra) => report(error, 'P1', source, extra);
|
|
115
|
+
//# sourceMappingURL=sentry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sentry.js","sourceRoot":"","sources":["../../../../../../src/angular-ui/lib/spotchecks/helpers/sentry.ts"],"names":[],"mappings":"AAAA,qGAAqG;AACrG,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAYnD,iEAAiE;AACjE,IAAI,UAAU,GAAwD,IAAI,CAAC;AAC3E,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,EAAkD,EAAE,EAAE;IACpF,UAAU,GAAG,EAAE,CAAC;AAClB,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,cAAc,GAAU,EAAE,CAAC;AAEjC,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAe,EAAE,IAA0B,EAAE,EAAE;IAC3E,cAAc,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;IAC5F,IAAI,cAAc,CAAC,MAAM,GAAG,eAAe;QAAE,cAAc,CAAC,KAAK,EAAE,CAAC;AACtE,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,GAAG,CAAC;AAClC,MAAM,SAAS,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,qBAAqB,CA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E,IAAI,CAAC;aAC/C,CAAC;QACF,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI;QAC5B,QAAQ,EAAE,YAAY;KACvB,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAc,EAAE,MAAmB,EAAE,KAA2B,EAAE,EAAE,CACjG,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AAErC,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,KAAc,EAAE,MAAmB,EAAE,KAA2B,EAAE,EAAE,CACjG,MAAM,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC","sourcesContent":["// SDK errors go to SurveySparrow's API (backend sentry.processSentryError), never to Sentry servers.\nimport { spotcheckStore } from '../state/store';\nimport { SDK_VERSION, FRAMEWORK } from './version';\n\nexport type ErrorSource =\n | 'SDK_INITIALIZATION'\n | 'SPOTCHECK_INITIALIZATION'\n | 'TRACK_SCREEN'\n | 'TRACK_EVENT'\n | 'WEBVIEW_ERROR'\n | 'CLOSE_SPOTCHECK'\n | 'APP_CRASH'\n | 'GENERAL';\n\n// Set by executables.ts at load time (avoids a circular import).\nlet executeRef: ((fn: string, params?: any) => Promise<any>) | null = null;\nexport const registerExecute = (fn: (fnName: string, params?: any) => Promise<any>) => {\n executeRef = fn;\n};\n\nconst MAX_BREADCRUMBS = 30;\nconst sdkBreadcrumbs: any[] = [];\n\nexport const addBreadcrumb = (message: string, data?: Record<string, any>) => {\n sdkBreadcrumbs.push({ category: 'spotcheck', message, data, timestamp: Date.now() / 1000 });\n if (sdkBreadcrumbs.length > MAX_BREADCRUMBS) sdkBreadcrumbs.shift();\n};\n\nconst MAX_BREADCRUMB_STRING = 200;\nconst capString = (value: string) => value.slice(0, MAX_BREADCRUMB_STRING);\n\n// Breadcrumb hook for backend functions; drops bad input and never throws.\nexport const safeAddBreadcrumb = (message: unknown, data?: unknown) => {\n try {\n if (typeof message !== 'string') return;\n let clean: Record<string, any> | undefined;\n const proto = data && typeof data === 'object' ? Object.getPrototypeOf(data) : undefined;\n if (proto === Object.prototype || proto === null) {\n clean = {};\n Object.keys(data as object).forEach((key) => {\n const value = (data as any)[key];\n if (typeof value === 'string') clean![key] = capString(value);\n else if (value === null || typeof value === 'number' || typeof value === 'boolean') clean![key] = value;\n });\n }\n addBreadcrumb(capString(message), clean);\n } catch {}\n};\n\n// Flags an error as reported so execute() does not report it again.\nconst markReported = (error: unknown) => {\n try {\n if (error !== null && typeof error === 'object') {\n Object.defineProperty(error, '__ssReported', { value: true, configurable: true });\n }\n } catch {}\n};\n\nexport const isReported = (error: unknown) => {\n try {\n return !!(error as any)?.__ssReported;\n } catch {\n return false;\n }\n};\n\n// Routes an event to the backend; never throws.\nconst sendToBackend = async (normalizedEvent: any) => {\n try {\n const result = executeRef\n ? await executeRef('sentry.processSentryError', {\n event: normalizedEvent,\n sdkType: FRAMEWORK,\n sdkVersion: SDK_VERSION,\n })\n : null;\n if (result) return;\n\n const { domainName, targetToken } = spotcheckStore.getState().SpotCheckState?.params || {};\n if (!domainName) return;\n await fetch(`https://${domainName}/api/internal/spotcheck/sdkErrors`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({\n errorMessage: normalizedEvent.errorMessage,\n sdkType: FRAMEWORK,\n sdkVersion: SDK_VERSION,\n level: normalizedEvent.tags?.error_priority === 'P0' ? 'fatal' : 'error',\n tags: normalizedEvent.tags,\n extra: normalizedEvent.extra,\n breadcrumbs: normalizedEvent.breadcrumbs,\n contexts: { user: { spotcheck_token: targetToken || '', spotcheck_domain_name: domainName } },\n }),\n }).catch(() => {});\n } catch {\n // Reporting must never break the host app.\n }\n};\n\nconst report = (error: unknown, priority: 'P0' | 'P1', source: ErrorSource, extra?: Record<string, any>) => {\n markReported(error);\n const err = error as any;\n sendToBackend({\n errorMessage: err?.message || String(error),\n tags: {\n error_priority: priority,\n severity: priority === 'P0' ? 'CRITICAL' : 'HIGH',\n errorType: source,\n },\n contexts: {},\n extra: extra || {},\n breadcrumbs: [...sdkBreadcrumbs],\n exceptions: [{\n type: err?.name || 'Error',\n value: err?.message || String(error),\n stack: String(err?.stack || '').slice(0, 2000),\n }],\n timestamp: Date.now() / 1000,\n platform: 'javascript',\n });\n};\n\nexport const captureP0Error = (error: unknown, source: ErrorSource, extra?: Record<string, any>) =>\n report(error, 'P0', source, extra);\n\nexport const captureP1Error = (error: unknown, source: ErrorSource, extra?: Record<string, any>) =>\n report(error, 'P1', source, extra);\n"]}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { captureP1Error } from './sentry';
|
|
2
|
+
// Same key as the legacy Ionic SDK, so existing installs keep their visitor.
|
|
3
|
+
const UUID_KEY = 'SurveySparrowUUID';
|
|
4
|
+
const uuidV4 = () => {
|
|
5
|
+
const c = typeof crypto !== 'undefined' ? crypto : null;
|
|
6
|
+
if (c === null || c === void 0 ? void 0 : c.randomUUID)
|
|
7
|
+
return c.randomUUID();
|
|
8
|
+
const bytes = new Uint8Array(16);
|
|
9
|
+
if (c === null || c === void 0 ? void 0 : c.getRandomValues)
|
|
10
|
+
c.getRandomValues(bytes);
|
|
11
|
+
else
|
|
12
|
+
for (let i = 0; i < 16; i++)
|
|
13
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
14
|
+
bytes[6] = (bytes[6] & 0x0f) | 0x40;
|
|
15
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
16
|
+
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');
|
|
17
|
+
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
18
|
+
};
|
|
19
|
+
export const generateTraceId = () => `${uuidV4()}-${Date.now()}`;
|
|
20
|
+
export const saveData = async (value) => {
|
|
21
|
+
try {
|
|
22
|
+
localStorage.setItem(UUID_KEY, value);
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
captureP1Error(error, 'GENERAL', { action: 'saveData', errorMessage: error === null || error === void 0 ? void 0 : error.message });
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
// isuuid: a new trace id; otherwise the stored visitor UUID.
|
|
29
|
+
export const loadData = async (isuuid = false) => {
|
|
30
|
+
try {
|
|
31
|
+
if (isuuid)
|
|
32
|
+
return generateTraceId();
|
|
33
|
+
return localStorage.getItem(UUID_KEY) || null;
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
captureP1Error(error, 'GENERAL', { action: 'loadData', isuuid, errorMessage: error === null || error === void 0 ? void 0 : error.message });
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=storage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../../../../src/angular-ui/lib/spotchecks/helpers/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,6EAA6E;AAC7E,MAAM,QAAQ,GAAG,mBAAmB,CAAC;AAErC,MAAM,MAAM,GAAG,GAAW,EAAE;IAC1B,MAAM,CAAC,GAAQ,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;IAC7D,IAAI,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,UAAU;QAAE,OAAO,CAAC,CAAC,UAAU,EAAE,CAAC;IACzC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC;IACjC,IAAI,CAAC,aAAD,CAAC,uBAAD,CAAC,CAAE,eAAe;QAAE,CAAC,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;;QAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,E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AL,KAAK,uBAAL,KAAK,CAAE,OAAO,EAAE,CAAC,CAAC;IACzF,CAAC;AACH,CAAC,CAAC;AAEF,6DAA6D;AAC7D,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAAE,SAAkB,KAAK,EAAE,EAAE;IACxD,IAAI,CAAC;QACH,IAAI,MAAM;YAAE,OAAO,eAAe,EAAE,CAAC;QACrC,OAAO,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC;IAChD,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,cAAc,CAAC,KAAK,EAAE,SAAS,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,OAAO,EAAE,CAAC,CAAC;QAC/F,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { captureP1Error } from './sentry';\n\n// Same key as the legacy Ionic SDK, so existing installs keep their visitor.\nconst UUID_KEY = 'SurveySparrowUUID';\n\nconst uuidV4 = (): string => {\n const c: any = typeof crypto !== 'undefined' ? crypto : null;\n if (c?.randomUUID) return c.randomUUID();\n const bytes = new Uint8Array(16);\n if (c?.getRandomValues) c.getRandomValues(bytes);\n else for (let i = 0; i < 16; i++) bytes[i] = Math.floor(Math.random() * 256);\n bytes[6] = (bytes[6] & 0x0f) | 0x40;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n};\n\nexport const generateTraceId = () => `${uuidV4()}-${Date.now()}`;\n\nexport const saveData = async (value: string) => {\n try {\n localStorage.setItem(UUID_KEY, value);\n } catch (error: any) {\n captureP1Error(error, 'GENERAL', { action: 'saveData', errorMessage: error?.message });\n }\n};\n\n// isuuid: a new trace id; otherwise the stored visitor UUID.\nexport const loadData = async (isuuid: boolean = false) => {\n try {\n if (isuuid) return generateTraceId();\n return localStorage.getItem(UUID_KEY) || null;\n } catch (error: any) {\n captureP1Error(error, 'GENERAL', { action: 'loadData', isuuid, errorMessage: error?.message });\n return null;\n }\n};\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface SurveyPageCallbacks {
|
|
2
|
+
onMessage: (data: string) => void;
|
|
3
|
+
onError: (error: {
|
|
4
|
+
nativeEvent: {
|
|
5
|
+
url: string;
|
|
6
|
+
description: string;
|
|
7
|
+
};
|
|
8
|
+
message: string;
|
|
9
|
+
}) => void;
|
|
10
|
+
}
|
|
11
|
+
export declare class SurveyPage {
|
|
12
|
+
private callbacks;
|
|
13
|
+
readonly iframe: HTMLIFrameElement;
|
|
14
|
+
private uri;
|
|
15
|
+
private origin;
|
|
16
|
+
private loadSeq;
|
|
17
|
+
private readonly onWindowMessage;
|
|
18
|
+
constructor(host: HTMLElement, callbacks: SurveyPageCallbacks);
|
|
19
|
+
load(uri: string): void;
|
|
20
|
+
injectJavaScript: (script: string) => boolean;
|
|
21
|
+
destroy(): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
// Loads the survey page from its own domain in a separate-origin iframe (as in 2.0.3), so the
|
|
2
|
+
// page can never reach the host app. The SDK and the page talk only through postMessage.
|
|
3
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
4
|
+
var t = {};
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
8
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
9
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
10
|
+
t[p[i]] = s[p[i]];
|
|
11
|
+
}
|
|
12
|
+
return t;
|
|
13
|
+
};
|
|
14
|
+
// Runs a backend injection with a stand-in window and keeps only the messages it dispatches.
|
|
15
|
+
// Scripts that touch the page DOM (CSS, re-measure) cannot cross origins and are dropped, as in 2.0.3.
|
|
16
|
+
const messagesFromScript = (script) => {
|
|
17
|
+
const messages = [];
|
|
18
|
+
const pageWindow = {
|
|
19
|
+
dispatchEvent: (event) => {
|
|
20
|
+
if ((event === null || event === void 0 ? void 0 : event.data) != null)
|
|
21
|
+
messages.push(event.data);
|
|
22
|
+
return true;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
class PageMessageEvent {
|
|
26
|
+
constructor(type, init) {
|
|
27
|
+
this.type = type;
|
|
28
|
+
this.data = init === null || init === void 0 ? void 0 : init.data;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
try {
|
|
32
|
+
// The host globals are shadowed so a DOM script fails here instead of touching the app.
|
|
33
|
+
new Function('window', 'MessageEvent', 'document', 'self', 'globalThis', 'parent', 'top', script)(pageWindow, PageMessageEvent, undefined, pageWindow, pageWindow, pageWindow, pageWindow);
|
|
34
|
+
}
|
|
35
|
+
catch (_a) {
|
|
36
|
+
// DOM-only script: nothing to send.
|
|
37
|
+
}
|
|
38
|
+
return messages;
|
|
39
|
+
};
|
|
40
|
+
// Same list as the survey page (rtls).
|
|
41
|
+
const RTL_LANGUAGES = ['ar', 'he', 'fa', 'ps', 'ur'];
|
|
42
|
+
// The web page sends its fields at the top level; the backend reads the RN/Expo shape { type, data }.
|
|
43
|
+
const toBackendMessage = (message) => {
|
|
44
|
+
var _a;
|
|
45
|
+
if (!message || typeof message !== 'object' || typeof message.type !== 'string')
|
|
46
|
+
return null;
|
|
47
|
+
if (message.type === 'resizeWindow') {
|
|
48
|
+
const height = (_a = message.size) === null || _a === void 0 ? void 0 : _a.height;
|
|
49
|
+
return typeof height === 'number' ? { type: 'spotCheckData', data: { currentQuestionSize: { height } } } : null;
|
|
50
|
+
}
|
|
51
|
+
if ('data' in message)
|
|
52
|
+
return message;
|
|
53
|
+
const { type } = message, data = __rest(message, ["type"]);
|
|
54
|
+
// The web languageChanged has only the code; add isRtl from the page's own RTL list.
|
|
55
|
+
if (type === 'languageChanged' && typeof data.code === 'string') {
|
|
56
|
+
data.isRtl = RTL_LANGUAGES.includes(data.code.split(/[-_]/)[0].toLowerCase());
|
|
57
|
+
}
|
|
58
|
+
return { type, data };
|
|
59
|
+
};
|
|
60
|
+
export class SurveyPage {
|
|
61
|
+
constructor(host, callbacks) {
|
|
62
|
+
this.callbacks = callbacks;
|
|
63
|
+
this.uri = '';
|
|
64
|
+
this.origin = '';
|
|
65
|
+
this.loadSeq = 0;
|
|
66
|
+
this.onWindowMessage = (event) => {
|
|
67
|
+
// Only the survey page in this iframe, from the survey domain.
|
|
68
|
+
if (event.source !== this.iframe.contentWindow || event.origin !== this.origin)
|
|
69
|
+
return;
|
|
70
|
+
const message = toBackendMessage(event.data);
|
|
71
|
+
if (message)
|
|
72
|
+
this.callbacks.onMessage(JSON.stringify(message));
|
|
73
|
+
};
|
|
74
|
+
// Same contract as the RN WebView ref the backend functions call; messages go by postMessage.
|
|
75
|
+
this.injectJavaScript = (script) => {
|
|
76
|
+
const win = this.iframe.contentWindow;
|
|
77
|
+
if (!win || !this.origin)
|
|
78
|
+
return false;
|
|
79
|
+
const messages = messagesFromScript(script);
|
|
80
|
+
messages.forEach((data) => {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
win.postMessage(data, this.origin);
|
|
83
|
+
// 2.0.3 sent the theme right after the survey state; the web page needs it to apply survey colours.
|
|
84
|
+
const themeInfo = (data === null || data === void 0 ? void 0 : data.type) === 'RESET_STATE' ? (_b = (_a = data.state) === null || _a === void 0 ? void 0 : _a.config) === null || _b === void 0 ? void 0 : _b.generatedCSS : null;
|
|
85
|
+
if (themeInfo)
|
|
86
|
+
win.postMessage({ type: 'THEME_UPDATE_SPOTCHECK', themeInfo }, this.origin);
|
|
87
|
+
});
|
|
88
|
+
return messages.length > 0;
|
|
89
|
+
};
|
|
90
|
+
this.iframe = document.createElement('iframe');
|
|
91
|
+
this.iframe.setAttribute('title', 'Survey');
|
|
92
|
+
this.iframe.setAttribute('allow', 'camera; microphone; geolocation; display-capture; autoplay; clipboard-read; clipboard-write; fullscreen');
|
|
93
|
+
this.iframe.setAttribute('allowfullscreen', '');
|
|
94
|
+
this.iframe.style.cssText = 'display:block;width:100%;height:100%;border:0;background:transparent;';
|
|
95
|
+
host.appendChild(this.iframe);
|
|
96
|
+
window.addEventListener('message', this.onWindowMessage);
|
|
97
|
+
}
|
|
98
|
+
load(uri) {
|
|
99
|
+
if (!uri || uri === this.uri)
|
|
100
|
+
return;
|
|
101
|
+
this.uri = uri;
|
|
102
|
+
this.origin = new URL(uri).origin;
|
|
103
|
+
const seq = ++this.loadSeq;
|
|
104
|
+
// A cross-origin iframe hides HTTP errors, so check the page first to report a failed load.
|
|
105
|
+
fetch(uri, { credentials: 'omit' })
|
|
106
|
+
.then((response) => {
|
|
107
|
+
if (!response.ok)
|
|
108
|
+
throw new Error(`Survey page failed with status ${response.status}`);
|
|
109
|
+
if (seq === this.loadSeq)
|
|
110
|
+
this.iframe.src = uri;
|
|
111
|
+
})
|
|
112
|
+
.catch((error) => {
|
|
113
|
+
if (seq !== this.loadSeq)
|
|
114
|
+
return;
|
|
115
|
+
// A later load() with the same uri retries.
|
|
116
|
+
this.uri = '';
|
|
117
|
+
const description = (error === null || error === void 0 ? void 0 : error.message) || String(error);
|
|
118
|
+
// message: readable text for the Sentry report (the RN event shape has none).
|
|
119
|
+
this.callbacks.onError({ nativeEvent: { url: uri, description }, message: description });
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
destroy() {
|
|
123
|
+
this.loadSeq++;
|
|
124
|
+
window.removeEventListener('message', this.onWindowMessage);
|
|
125
|
+
this.iframe.remove();
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=survey-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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EAA8E;YAC9E,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,WAAW,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC;QAC3F,CAAC,CAAC,CAAC;IACP,CAAC;IAgBD,OAAO;QACL,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QAC5D,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IACvB,CAAC;CACF","sourcesContent":["// Loads the survey page from its own domain in a separate-origin iframe (as in 2.0.3), so the\n// page can never reach the host app. The SDK and the page talk only through postMessage.\n\nexport interface SurveyPageCallbacks {\n onMessage: (data: string) => void;\n onError: (error: { nativeEvent: { url: string; description: string }; message: string }) => void;\n}\n\n// Runs a backend injection with a stand-in window and keeps only the messages it dispatches.\n// Scripts that touch the page DOM (CSS, re-measure) cannot cross origins and are dropped, as in 2.0.3.\nconst messagesFromScript = (script: string): any[] => {\n const messages: any[] = [];\n const pageWindow = {\n dispatchEvent: (event: any) => {\n if (event?.data != null) messages.push(event.data);\n return true;\n },\n };\n class PageMessageEvent {\n data: any;\n constructor(public type: string, init?: { data?: any }) {\n this.data = init?.data;\n }\n }\n try {\n // The host globals are shadowed so a DOM script fails here instead of touching the app.\n new Function('window', 'MessageEvent', 'document', 'self', 'globalThis', 'parent', 'top', script)(\n pageWindow, PageMessageEvent, undefined, pageWindow, pageWindow, pageWindow, pageWindow,\n );\n } catch {\n // DOM-only script: nothing to send.\n }\n return messages;\n};\n\n// Same list as the survey page (rtls).\nconst RTL_LANGUAGES = ['ar', 'he', 'fa', 'ps', 'ur'];\n\n// The web page sends its fields at the top level; the backend reads the RN/Expo shape { type, data }.\nconst toBackendMessage = (message: any): any | null => {\n if (!message || typeof message !== 'object' || typeof message.type !== 'string') return null;\n if (message.type === 'resizeWindow') {\n const height = message.size?.height;\n return typeof height === 'number' ? { type: 'spotCheckData', data: { currentQuestionSize: { height } } } : null;\n }\n if ('data' in message) return message;\n const { type, ...data } = message;\n // The web languageChanged has only the code; add isRtl from the page's own RTL list.\n if (type === 'languageChanged' && typeof data.code === 'string') {\n data.isRtl = RTL_LANGUAGES.includes(data.code.split(/[-_]/)[0].toLowerCase());\n }\n return { type, data };\n};\n\nexport class SurveyPage {\n readonly iframe: HTMLIFrameElement;\n private uri = '';\n private origin = '';\n private loadSeq = 0;\n private readonly onWindowMessage = (event: MessageEvent) => {\n // Only the survey page in this iframe, from the survey domain.\n if (event.source !== this.iframe.contentWindow || event.origin !== this.origin) return;\n const message = toBackendMessage(event.data);\n if (message) this.callbacks.onMessage(JSON.stringify(message));\n };\n\n constructor(host: HTMLElement, private callbacks: SurveyPageCallbacks) {\n this.iframe = document.createElement('iframe');\n this.iframe.setAttribute('title', 'Survey');\n this.iframe.setAttribute(\n 'allow',\n 'camera; microphone; geolocation; display-capture; autoplay; clipboard-read; clipboard-write; fullscreen',\n );\n this.iframe.setAttribute('allowfullscreen', '');\n this.iframe.style.cssText = 'display:block;width:100%;height:100%;border:0;background:transparent;';\n host.appendChild(this.iframe);\n window.addEventListener('message', this.onWindowMessage);\n }\n\n load(uri: string): void {\n if (!uri || uri === this.uri) return;\n this.uri = uri;\n this.origin = new URL(uri).origin;\n const seq = ++this.loadSeq;\n // A cross-origin iframe hides HTTP errors, so check the page first to report a failed load.\n fetch(uri, { credentials: 'omit' })\n .then((response) => {\n if (!response.ok) throw new Error(`Survey page failed with status ${response.status}`);\n if (seq === this.loadSeq) this.iframe.src = uri;\n })\n .catch((error: any) => {\n if (seq !== this.loadSeq) return;\n // A later load() with the same uri retries.\n this.uri = '';\n const description = error?.message || String(error);\n // message: readable text for the Sentry report (the RN event shape has none).\n this.callbacks.onError({ nativeEvent: { url: uri, description }, message: description });\n });\n }\n\n // Same contract as the RN WebView ref the backend functions call; messages go by postMessage.\n injectJavaScript = (script: string): boolean => {\n const win = this.iframe.contentWindow;\n if (!win || !this.origin) return false;\n const messages = messagesFromScript(script);\n messages.forEach((data) => {\n win.postMessage(data, this.origin);\n // 2.0.3 sent the theme right after the survey state; the web page needs it to apply survey colours.\n const themeInfo = data?.type === 'RESET_STATE' ? data.state?.config?.generatedCSS : null;\n if (themeInfo) win.postMessage({ type: 'THEME_UPDATE_SPOTCHECK', themeInfo }, this.origin);\n });\n return messages.length > 0;\n };\n\n destroy(): void {\n this.loadSeq++;\n window.removeEventListener('message', this.onWindowMessage);\n this.iframe.remove();\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../../../../src/angular-ui/lib/spotchecks/helpers/version.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,MAAM,CAAC,MAAM,WAAW,GAAG,cAAc,CAAC;AAC1C,MAAM,CAAC,MAAM,SAAS,GAAG,OAAO,CAAC","sourcesContent":["// Keep in sync with package.json \"version\".\nexport const SDK_VERSION = '2.0.4-beta.1';\nexport const FRAMEWORK = 'ionic';\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export { initializeSpotChecks, trackScreen, trackEvent } from './
|
|
2
|
-
export { addSpotCheckListener
|
|
3
|
-
export type {
|
|
1
|
+
export { initializeSpotChecks, trackScreen, trackEvent, closeSpotChecks, SDK_VERSION, } from './spotcheck';
|
|
2
|
+
export { addSpotCheckListener } from './helpers/listener';
|
|
3
|
+
export type { SpotCheckEventType } from './helpers/listener';
|
|
4
|
+
export type { UserDetails, Variables, CustomProperties, TrackScreenOptions, TrackScreenProps, TrackEventProps, InitializeSpotChecksProps, SpotcheckProps, SsSpotcheckListener, } from './types';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { initializeSpotChecks, trackScreen, trackEvent } from './
|
|
2
|
-
export { addSpotCheckListener
|
|
1
|
+
export { initializeSpotChecks, trackScreen, trackEvent, closeSpotChecks, SDK_VERSION, } from './spotcheck';
|
|
2
|
+
export { addSpotCheckListener } from './helpers/listener';
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/angular-ui/lib/spotchecks/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/angular-ui/lib/spotchecks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,WAAW,EACX,UAAU,EACV,eAAe,EACf,WAAW,GACZ,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAC","sourcesContent":["export {\n initializeSpotChecks,\n trackScreen,\n trackEvent,\n closeSpotChecks,\n SDK_VERSION,\n} from './spotcheck';\nexport { addSpotCheckListener } from './helpers/listener';\nexport type { SpotCheckEventType } from './helpers/listener';\nexport type {\n UserDetails,\n Variables,\n CustomProperties,\n TrackScreenOptions,\n TrackScreenProps,\n TrackEventProps,\n InitializeSpotChecksProps,\n SpotcheckProps,\n SsSpotcheckListener,\n} from './types';\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SpotcheckProps, TrackEventProps, TrackScreenOptions, TrackScreenProps } from './types';
|
|
2
|
+
export { SDK_VERSION } from './helpers/version';
|
|
3
|
+
export declare const initializeSpotChecks: (params: SpotcheckProps) => Promise<void>;
|
|
4
|
+
export declare function trackScreen(screen: string, options?: TrackScreenOptions): Promise<void>;
|
|
5
|
+
export declare function trackScreen(props: TrackScreenProps): Promise<void>;
|
|
6
|
+
export declare function trackEvent(screen: string, event: Record<string, any>, options?: TrackScreenOptions): Promise<void>;
|
|
7
|
+
export declare function trackEvent(props: TrackEventProps): Promise<void>;
|
|
8
|
+
export declare function closeSpotChecks(): Promise<void>;
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { componentStore, functionStore, spotcheckStore } from './state/store';
|
|
13
|
+
import { execute, markInitialized } from './helpers/executables';
|
|
14
|
+
import { setListener } from './helpers/listener';
|
|
15
|
+
import { getDeviceFacts, getVisitorInfo, loadDeviceInfo } from './helpers/device';
|
|
16
|
+
import { addBreadcrumb, captureP0Error } from './helpers/sentry';
|
|
17
|
+
import { FRAMEWORK } from './helpers/version';
|
|
18
|
+
export { SDK_VERSION } from './helpers/version';
|
|
19
|
+
const INIT_TIMEOUT_MS = 15000;
|
|
20
|
+
// Backend functions, schemas and page script for this SDK (framework=ionic).
|
|
21
|
+
const getAllSpotcheckFunctions = async (domainName) => {
|
|
22
|
+
const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;
|
|
23
|
+
const timer = setTimeout(() => controller === null || controller === void 0 ? void 0 : controller.abort(), INIT_TIMEOUT_MS);
|
|
24
|
+
try {
|
|
25
|
+
const response = await fetch(`https://${domainName}/api/internal/spotcheck/mobile/init?framework=${FRAMEWORK}`, { signal: controller === null || controller === void 0 ? void 0 : controller.signal, cache: 'no-store' });
|
|
26
|
+
if (!response.ok)
|
|
27
|
+
throw new Error(`mobile/init failed with status ${response.status}`);
|
|
28
|
+
const data = await response.json().catch(() => null);
|
|
29
|
+
// A non-JSON 200 (e.g. captive portal) counts as a failed init.
|
|
30
|
+
if (!data || typeof data !== 'object' || typeof data.initializeSpotcheckComponent !== 'string') {
|
|
31
|
+
throw new Error('Invalid mobile/init response');
|
|
32
|
+
}
|
|
33
|
+
const { componentSchemas, config } = data, functions = __rest(data, ["componentSchemas", "config"]);
|
|
34
|
+
functionStore.dispatch(Object.assign(Object.assign({}, functions), { isLoaded: true }));
|
|
35
|
+
componentStore.dispatch({ schemas: componentSchemas || {}, config: config || {}, isLoaded: Boolean(componentSchemas) });
|
|
36
|
+
return data;
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
captureP0Error(error, 'SPOTCHECK_INITIALIZATION', {
|
|
40
|
+
component: 'getAllSpotcheckFunctions',
|
|
41
|
+
action: 'fetchFunctions',
|
|
42
|
+
domainName,
|
|
43
|
+
errorMessage: error === null || error === void 0 ? void 0 : error.message,
|
|
44
|
+
});
|
|
45
|
+
console.error('Error fetching spotcheck functions:', error);
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
finally {
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
// Synchronous: trackScreen must reach execute in the same tick as a following trackEvent.
|
|
53
|
+
const refreshVisitor = () => {
|
|
54
|
+
try {
|
|
55
|
+
spotcheckStore.dispatch({ params: { visitor: getVisitorInfo() } });
|
|
56
|
+
}
|
|
57
|
+
catch (_a) { }
|
|
58
|
+
};
|
|
59
|
+
// Init retry: a failed init (e.g. offline at launch) is retried on the next track call.
|
|
60
|
+
const INIT_RETRY_GAP_MS = 10000;
|
|
61
|
+
let lastInitParams = null;
|
|
62
|
+
let initStatus = 'idle';
|
|
63
|
+
let lastInitAttempt = 0;
|
|
64
|
+
const retryInitIfFailed = () => {
|
|
65
|
+
if (initStatus !== 'failed' || !lastInitParams)
|
|
66
|
+
return;
|
|
67
|
+
if (Date.now() - lastInitAttempt < INIT_RETRY_GAP_MS)
|
|
68
|
+
return;
|
|
69
|
+
initializeSpotChecks(lastInitParams).catch(() => { });
|
|
70
|
+
};
|
|
71
|
+
export const initializeSpotChecks = async (params) => {
|
|
72
|
+
lastInitParams = params;
|
|
73
|
+
initStatus = 'running';
|
|
74
|
+
lastInitAttempt = Date.now();
|
|
75
|
+
try {
|
|
76
|
+
setListener(params === null || params === void 0 ? void 0 : params.listener);
|
|
77
|
+
if (params === null || params === void 0 ? void 0 : params.domainName)
|
|
78
|
+
spotcheckStore.dispatch({ params: { domainName: params.domainName } });
|
|
79
|
+
await loadDeviceInfo();
|
|
80
|
+
refreshVisitor();
|
|
81
|
+
const device = await getDeviceFacts();
|
|
82
|
+
await getAllSpotcheckFunctions(params.domainName);
|
|
83
|
+
const { listener } = params, initParams = __rest(params, ["listener"]);
|
|
84
|
+
await execute('initializeSpotcheckComponent', Object.assign(Object.assign({}, initParams), { framework: FRAMEWORK, device }));
|
|
85
|
+
await markInitialized();
|
|
86
|
+
initStatus = 'done';
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
// Legacy never threw into the host app; failures go to the backend and the console.
|
|
90
|
+
console.error('Error initializing spotchecks:', error);
|
|
91
|
+
initStatus = 'failed';
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const resolveTrackOptions = (input) => {
|
|
95
|
+
var _a, _b, _c;
|
|
96
|
+
return ({
|
|
97
|
+
variables: (_a = input === null || input === void 0 ? void 0 : input.variables) !== null && _a !== void 0 ? _a : {},
|
|
98
|
+
customProperties: (_b = input === null || input === void 0 ? void 0 : input.customProperties) !== null && _b !== void 0 ? _b : {},
|
|
99
|
+
userDetails: (_c = input === null || input === void 0 ? void 0 : input.userDetails) !== null && _c !== void 0 ? _c : {},
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
export async function trackScreen(screenOrProps, optionsArg) {
|
|
103
|
+
const screen = typeof screenOrProps === 'string' ? screenOrProps : screenOrProps === null || screenOrProps === void 0 ? void 0 : screenOrProps.screen;
|
|
104
|
+
const options = resolveTrackOptions(typeof screenOrProps === 'string' ? optionsArg : screenOrProps === null || screenOrProps === void 0 ? void 0 : screenOrProps.options);
|
|
105
|
+
if (!screen) {
|
|
106
|
+
console.error('trackScreen: `screen` is required');
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
addBreadcrumb('trackScreen', { screen });
|
|
110
|
+
retryInitIfFailed();
|
|
111
|
+
try {
|
|
112
|
+
refreshVisitor();
|
|
113
|
+
await execute('trackScreen', { screen, options });
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
// Legacy only logged; never throw into the host app.
|
|
117
|
+
console.error('Error tracking screen:', error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
export async function trackEvent(screenOrProps, eventArg, optionsArg) {
|
|
121
|
+
const isString = typeof screenOrProps === 'string';
|
|
122
|
+
const screen = isString ? screenOrProps : screenOrProps === null || screenOrProps === void 0 ? void 0 : screenOrProps.screen;
|
|
123
|
+
const event = isString ? eventArg : screenOrProps === null || screenOrProps === void 0 ? void 0 : screenOrProps.event;
|
|
124
|
+
if (!screen) {
|
|
125
|
+
console.error('trackEvent: `screen` is required');
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (event == null) {
|
|
129
|
+
console.error('trackEvent: `event` is required');
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const options = resolveTrackOptions(isString ? optionsArg : screenOrProps.options);
|
|
133
|
+
addBreadcrumb('trackEvent', { screen, event: Object.keys(event || {}).join(',') });
|
|
134
|
+
retryInitIfFailed();
|
|
135
|
+
try {
|
|
136
|
+
await execute('trackEvent', { screen, event, options });
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
console.error('Error tracking event:', error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Closes any open spotcheck and its button (screen changes the SDK can't detect).
|
|
143
|
+
export async function closeSpotChecks() {
|
|
144
|
+
addBreadcrumb('closeSpotChecks', {});
|
|
145
|
+
await execute('handleNavigationChange', { reason: 'close' });
|
|
146
|
+
}
|
|
147
|
+
//# sourceMappingURL=spotcheck.js.map
|
|
@@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,OAAO,EAAE,CAAC,CAAC;IAC1D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE,KAAK,CAAC,CAAC;IAChD,CAAC;AACH,CAAC;AAED,kFAAkF;AAClF,MAAM,CAAC,KAAK,UAAU,eAAe;IACnC,aAAa,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;IACrC,MAAM,OAAO,CAAC,wBAAwB,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAC/D,CAAC","sourcesContent":["import { componentStore, functionStore, spotcheckStore } from './state/store';\nimport { execute, markInitialized } from './helpers/executables';\nimport { setListener } from './helpers/listener';\nimport { getDeviceFacts, getVisitorInfo, loadDeviceInfo } from './helpers/device';\nimport { addBreadcrumb, captureP0Error } from './helpers/sentry';\nimport { FRAMEWORK } from './helpers/version';\nimport type {\n SpotcheckProps,\n TrackEventProps,\n TrackScreenOptions,\n TrackScreenProps,\n} from './types';\n\nexport { SDK_VERSION } from './helpers/version';\n\nconst INIT_TIMEOUT_MS = 15000;\n\n// Backend functions, schemas and page script for this SDK (framework=ionic).\nconst getAllSpotcheckFunctions = async (domainName: string) => {\n const controller = typeof AbortController !== 'undefined' ? new AbortController() : null;\n const timer = setTimeout(() => controller?.abort(), INIT_TIMEOUT_MS);\n try {\n const response = await fetch(\n `https://${domainName}/api/internal/spotcheck/mobile/init?framework=${FRAMEWORK}`,\n { signal: controller?.signal, cache: 'no-store' },\n );\n if (!response.ok) throw new Error(`mobile/init failed with status ${response.status}`);\n const data = await response.json().catch(() => null);\n // A non-JSON 200 (e.g. captive portal) counts as a failed init.\n if (!data || typeof data !== 'object' || typeof data.initializeSpotcheckComponent !== 'string') {\n throw new Error('Invalid mobile/init response');\n }\n const { componentSchemas, config, ...functions } = data;\n functionStore.dispatch({ ...functions, isLoaded: true });\n componentStore.dispatch({ schemas: componentSchemas || {}, config: config || {}, isLoaded: Boolean(componentSchemas) });\n return data;\n } catch (error: any) {\n captureP0Error(error, 'SPOTCHECK_INITIALIZATION', {\n component: 'getAllSpotcheckFunctions',\n action: 'fetchFunctions',\n domainName,\n errorMessage: error?.message,\n });\n console.error('Error fetching spotcheck functions:', error);\n throw error;\n } finally {\n clearTimeout(timer);\n }\n};\n\n// Synchronous: trackScreen must reach execute in the same tick as a following trackEvent.\nconst refreshVisitor = () => {\n try {\n spotcheckStore.dispatch({ params: { visitor: getVisitorInfo() } });\n } catch {}\n};\n\n// Init retry: a failed init (e.g. offline at launch) is retried on the next track call.\nconst INIT_RETRY_GAP_MS = 10000;\nlet lastInitParams: SpotcheckProps | null = null;\nlet initStatus: 'idle' | 'running' | 'done' | 'failed' = 'idle';\nlet lastInitAttempt = 0;\n\nconst retryInitIfFailed = () => {\n if (initStatus !== 'failed' || !lastInitParams) return;\n if (Date.now() - lastInitAttempt < INIT_RETRY_GAP_MS) return;\n initializeSpotChecks(lastInitParams).catch(() => {});\n};\n\nexport const initializeSpotChecks = async (params: SpotcheckProps): Promise<void> => {\n lastInitParams = params;\n initStatus = 'running';\n lastInitAttempt = Date.now();\n try {\n setListener(params?.listener);\n if (params?.domainName) spotcheckStore.dispatch({ params: { domainName: params.domainName } });\n await loadDeviceInfo();\n refreshVisitor();\n const device = await getDeviceFacts();\n await getAllSpotcheckFunctions(params.domainName);\n const { listener, ...initParams } = params;\n await execute('initializeSpotcheckComponent', { ...initParams, framework: FRAMEWORK, device });\n await markInitialized();\n initStatus = 'done';\n } catch (error: any) {\n // Legacy never threw into the host app; failures go to the backend and the console.\n console.error('Error initializing spotchecks:', error);\n initStatus = 'failed';\n }\n};\n\nconst resolveTrackOptions = (input?: TrackScreenOptions) => ({\n variables: input?.variables ?? {},\n customProperties: input?.customProperties ?? {},\n userDetails: input?.userDetails ?? {},\n});\n\nexport async function trackScreen(screen: string, options?: TrackScreenOptions): Promise<void>;\nexport async function trackScreen(props: TrackScreenProps): Promise<void>;\nexport async function trackScreen(screenOrProps: string | TrackScreenProps, optionsArg?: TrackScreenOptions) {\n const screen = typeof screenOrProps === 'string' ? screenOrProps : screenOrProps?.screen;\n const options = resolveTrackOptions(typeof screenOrProps === 'string' ? optionsArg : screenOrProps?.options);\n if (!screen) {\n console.error('trackScreen: `screen` is required');\n return;\n }\n addBreadcrumb('trackScreen', { screen });\n retryInitIfFailed();\n try {\n refreshVisitor();\n await execute('trackScreen', { screen, options });\n } catch (error) {\n // Legacy only logged; never throw into the host app.\n console.error('Error tracking screen:', error);\n }\n}\n\nexport async function trackEvent(screen: string, event: Record<string, any>, options?: TrackScreenOptions): Promise<void>;\nexport async function trackEvent(props: TrackEventProps): Promise<void>;\nexport async function trackEvent(\n screenOrProps: string | TrackEventProps,\n eventArg?: Record<string, any>,\n optionsArg?: TrackScreenOptions,\n) {\n const isString = typeof screenOrProps === 'string';\n const screen = isString ? screenOrProps : screenOrProps?.screen;\n const event = isString ? eventArg : screenOrProps?.event;\n if (!screen) {\n console.error('trackEvent: `screen` is required');\n return;\n }\n if (event == null) {\n console.error('trackEvent: `event` is required');\n return;\n }\n const options = resolveTrackOptions(isString ? optionsArg : screenOrProps.options);\n addBreadcrumb('trackEvent', { screen, event: Object.keys(event || {}).join(',') });\n retryInitIfFailed();\n try {\n await execute('trackEvent', { screen, event, options });\n } catch (error) {\n console.error('Error tracking event:', error);\n }\n}\n\n// Closes any open spotcheck and its button (screen changes the SDK can't detect).\nexport async function closeSpotChecks(): Promise<void> {\n addBreadcrumb('closeSpotChecks', {});\n await execute('handleNavigationChange', { reason: 'close' });\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type Listener = () => void;
|
|
2
|
+
export declare class Store<T> {
|
|
3
|
+
private state;
|
|
4
|
+
private reducer;
|
|
5
|
+
private listeners;
|
|
6
|
+
constructor(state: T, reducer: (state: T, update: any) => T);
|
|
7
|
+
getState(): T;
|
|
8
|
+
dispatch(update: any): void;
|
|
9
|
+
subscribe(listener: Listener): () => void;
|
|
10
|
+
}
|
|
11
|
+
export declare const spotcheckStore: Store<any>;
|
|
12
|
+
export declare const functionStore: Store<any>;
|
|
13
|
+
export declare const componentStore: Store<any>;
|
|
14
|
+
export {};
|