@robotical/webapp-types 3.16.11 → 3.16.13
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.
|
@@ -1,11 +1,26 @@
|
|
|
1
|
+
import type { UserDeviceInfo } from "../../types/userDeviceInfo";
|
|
1
2
|
export type FeedbackRating = 1 | 2 | 3 | 4 | 5;
|
|
2
3
|
export type FeedbackSource = "emoji-modal" | "detailed-feedback" | "help-bug-report";
|
|
4
|
+
export type FeedbackAppRuntime = "phone-app" | "web-app";
|
|
5
|
+
export type FeedbackEnvironment = {
|
|
6
|
+
appRuntime: FeedbackAppRuntime;
|
|
7
|
+
isPhoneApp: boolean;
|
|
8
|
+
deviceInfo: Partial<UserDeviceInfo> | null;
|
|
9
|
+
userAgent: string | null;
|
|
10
|
+
language: string | null;
|
|
11
|
+
viewport: {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
devicePixelRatio: number;
|
|
15
|
+
} | null;
|
|
16
|
+
};
|
|
3
17
|
export type SubmitFeedbackInput = {
|
|
4
18
|
rating?: FeedbackRating;
|
|
5
19
|
message?: string;
|
|
6
20
|
email?: string;
|
|
7
21
|
context?: Record<string, unknown> | null;
|
|
8
22
|
source: FeedbackSource;
|
|
23
|
+
environment?: FeedbackEnvironment;
|
|
9
24
|
};
|
|
10
25
|
export type FeedbackRecord = {
|
|
11
26
|
rating: FeedbackRating | null;
|
|
@@ -13,6 +28,7 @@ export type FeedbackRecord = {
|
|
|
13
28
|
email: string | null;
|
|
14
29
|
source: FeedbackSource;
|
|
15
30
|
context: Record<string, unknown> | null;
|
|
31
|
+
environment: FeedbackEnvironment;
|
|
16
32
|
timestamp: string;
|
|
17
33
|
text: string;
|
|
18
34
|
};
|
|
@@ -20,6 +36,7 @@ export type SubmitFeedbackResult = {
|
|
|
20
36
|
record: FeedbackRecord;
|
|
21
37
|
slackDelivered: boolean;
|
|
22
38
|
};
|
|
39
|
+
export declare function collectFeedbackEnvironment(): FeedbackEnvironment;
|
|
23
40
|
export declare function buildFeedbackText(record: FeedbackRecord): string;
|
|
24
41
|
export declare function createFeedbackRecord(input: SubmitFeedbackInput): FeedbackRecord;
|
|
25
42
|
export declare function submitFeedback(input: SubmitFeedbackInput): Promise<SubmitFeedbackResult>;
|
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
1
12
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
13
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
14
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -36,6 +47,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
47
|
};
|
|
37
48
|
import Logger from "../../services/logger/Logger";
|
|
38
49
|
import randomHashGenerator from "../helpers/randomHashGenerator";
|
|
50
|
+
import isPhoneApp from "../phone-app-communication/is-phone-app";
|
|
39
51
|
var SHOW_LOGS = true;
|
|
40
52
|
var TAG = "submitFeedback";
|
|
41
53
|
var WEB_APP_FEEDBACK_DB_URL = "https://web-app-bug-reports-default-rtdb.europe-west1.firebasedatabase.app/";
|
|
@@ -44,8 +56,118 @@ function normalizeOptionalString(value) {
|
|
|
44
56
|
var trimmedValue = value === null || value === void 0 ? void 0 : value.trim();
|
|
45
57
|
return trimmedValue ? trimmedValue : null;
|
|
46
58
|
}
|
|
59
|
+
function normalizeOptionalRecordString(value) {
|
|
60
|
+
var _a;
|
|
61
|
+
if (typeof value !== "string") {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
return (_a = normalizeOptionalString(value)) !== null && _a !== void 0 ? _a : null;
|
|
65
|
+
}
|
|
66
|
+
function getNavigatorValue(reader) {
|
|
67
|
+
if (typeof navigator === "undefined") {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return reader(navigator);
|
|
71
|
+
}
|
|
72
|
+
function getWindowValue(reader) {
|
|
73
|
+
if (typeof window === "undefined") {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
return reader(window);
|
|
77
|
+
}
|
|
78
|
+
export function collectFeedbackEnvironment() {
|
|
79
|
+
var _a, _b;
|
|
80
|
+
var runningInPhoneApp = (_a = getWindowValue(function () { return isPhoneApp(); })) !== null && _a !== void 0 ? _a : false;
|
|
81
|
+
var deviceInfo = (_b = getWindowValue(function (windowObject) { var _a; return (_a = windowObject.applicationManager) === null || _a === void 0 ? void 0 : _a.deviceInfo; })) !== null && _b !== void 0 ? _b : null;
|
|
82
|
+
var viewport = getWindowValue(function (windowObject) { return ({
|
|
83
|
+
width: windowObject.innerWidth,
|
|
84
|
+
height: windowObject.innerHeight,
|
|
85
|
+
devicePixelRatio: windowObject.devicePixelRatio || 1,
|
|
86
|
+
}); });
|
|
87
|
+
return {
|
|
88
|
+
appRuntime: runningInPhoneApp ? "phone-app" : "web-app",
|
|
89
|
+
isPhoneApp: runningInPhoneApp,
|
|
90
|
+
deviceInfo: deviceInfo ? __assign({}, deviceInfo) : null,
|
|
91
|
+
userAgent: getNavigatorValue(function (navigatorObject) { return navigatorObject.userAgent; }),
|
|
92
|
+
language: getNavigatorValue(function (navigatorObject) { return navigatorObject.language; }),
|
|
93
|
+
viewport: viewport,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function getRuntimeLabel(appRuntime) {
|
|
97
|
+
return appRuntime === "phone-app" ? "Phone app" : "Web app";
|
|
98
|
+
}
|
|
99
|
+
function getPhoneDeviceLines(deviceInfo) {
|
|
100
|
+
var manufacturer = normalizeOptionalRecordString(deviceInfo.manufacturer);
|
|
101
|
+
var model = normalizeOptionalRecordString(deviceInfo.model);
|
|
102
|
+
var deviceName = normalizeOptionalRecordString(deviceInfo.deviceName);
|
|
103
|
+
var systemName = normalizeOptionalRecordString(deviceInfo.systemName);
|
|
104
|
+
var systemVersion = normalizeOptionalRecordString(deviceInfo.systemVersion);
|
|
105
|
+
var appVersion = normalizeOptionalRecordString(deviceInfo.appVersion);
|
|
106
|
+
var buildNumber = normalizeOptionalRecordString(deviceInfo.buildNumber);
|
|
107
|
+
var deviceId = normalizeOptionalRecordString(deviceInfo.deviceId);
|
|
108
|
+
var lines = [];
|
|
109
|
+
var deviceLabel = [manufacturer, model].filter(Boolean).join(" ").trim();
|
|
110
|
+
if (deviceLabel) {
|
|
111
|
+
lines.push("Device: ".concat(deviceLabel));
|
|
112
|
+
}
|
|
113
|
+
if (deviceName && deviceName !== deviceLabel) {
|
|
114
|
+
lines.push("Device name: ".concat(deviceName));
|
|
115
|
+
}
|
|
116
|
+
var osLabel = [systemName, systemVersion].filter(Boolean).join(" ").trim();
|
|
117
|
+
if (osLabel) {
|
|
118
|
+
lines.push("OS: ".concat(osLabel));
|
|
119
|
+
}
|
|
120
|
+
var appVersionLabel = [appVersion, buildNumber ? "(".concat(buildNumber, ")") : null]
|
|
121
|
+
.filter(Boolean)
|
|
122
|
+
.join(" ");
|
|
123
|
+
if (appVersionLabel) {
|
|
124
|
+
lines.push("App version: ".concat(appVersionLabel));
|
|
125
|
+
}
|
|
126
|
+
if (deviceId) {
|
|
127
|
+
lines.push("Device ID: ".concat(deviceId));
|
|
128
|
+
}
|
|
129
|
+
return lines;
|
|
130
|
+
}
|
|
131
|
+
function getWebDeviceLines(deviceInfo, environment) {
|
|
132
|
+
var browserVersion = normalizeOptionalRecordString(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.version);
|
|
133
|
+
var systemName = normalizeOptionalRecordString(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.systemName);
|
|
134
|
+
var appVersion = normalizeOptionalRecordString(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.appVersion);
|
|
135
|
+
var deviceId = normalizeOptionalRecordString(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.deviceId);
|
|
136
|
+
var host = normalizeOptionalRecordString(deviceInfo === null || deviceInfo === void 0 ? void 0 : deviceInfo.bundleId);
|
|
137
|
+
var lines = [];
|
|
138
|
+
if (browserVersion) {
|
|
139
|
+
lines.push("Browser: ".concat([browserVersion, systemName ? "on ".concat(systemName) : null]
|
|
140
|
+
.filter(Boolean)
|
|
141
|
+
.join(" ")));
|
|
142
|
+
}
|
|
143
|
+
else if (environment.userAgent) {
|
|
144
|
+
lines.push("Browser: ".concat(environment.userAgent));
|
|
145
|
+
}
|
|
146
|
+
if (!browserVersion && systemName) {
|
|
147
|
+
lines.push("OS: ".concat(systemName));
|
|
148
|
+
}
|
|
149
|
+
if (host) {
|
|
150
|
+
lines.push("Host: ".concat(host));
|
|
151
|
+
}
|
|
152
|
+
if (appVersion) {
|
|
153
|
+
lines.push("App version: ".concat(appVersion));
|
|
154
|
+
}
|
|
155
|
+
if (deviceId) {
|
|
156
|
+
lines.push("Device ID: ".concat(deviceId));
|
|
157
|
+
}
|
|
158
|
+
return lines;
|
|
159
|
+
}
|
|
160
|
+
function getEnvironmentTextLines(environment) {
|
|
161
|
+
var _a;
|
|
162
|
+
var lines = ["App: ".concat(getRuntimeLabel(environment.appRuntime))];
|
|
163
|
+
var deviceLines = environment.appRuntime === "phone-app"
|
|
164
|
+
? getPhoneDeviceLines((_a = environment.deviceInfo) !== null && _a !== void 0 ? _a : {})
|
|
165
|
+
: getWebDeviceLines(environment.deviceInfo, environment);
|
|
166
|
+
return lines.concat(deviceLines);
|
|
167
|
+
}
|
|
47
168
|
export function buildFeedbackText(record) {
|
|
48
169
|
var lines = ["Source: ".concat(record.source)];
|
|
170
|
+
lines.push.apply(lines, getEnvironmentTextLines(record.environment));
|
|
49
171
|
var page = record.context && typeof record.context.page === "string"
|
|
50
172
|
? record.context.page
|
|
51
173
|
: null;
|
|
@@ -71,16 +193,18 @@ export function buildFeedbackText(record) {
|
|
|
71
193
|
return lines.join("\n");
|
|
72
194
|
}
|
|
73
195
|
export function createFeedbackRecord(input) {
|
|
74
|
-
var _a;
|
|
196
|
+
var _a, _b;
|
|
75
197
|
var normalizedMessage = normalizeOptionalString(input.message);
|
|
76
198
|
var normalizedEmail = normalizeOptionalString(input.email);
|
|
77
199
|
var timestamp = new Date().toISOString();
|
|
200
|
+
var environment = (_a = input.environment) !== null && _a !== void 0 ? _a : collectFeedbackEnvironment();
|
|
78
201
|
var record = {
|
|
79
|
-
rating: (
|
|
202
|
+
rating: (_b = input.rating) !== null && _b !== void 0 ? _b : null,
|
|
80
203
|
message: normalizedMessage,
|
|
81
204
|
email: normalizedEmail,
|
|
82
205
|
source: input.source,
|
|
83
206
|
context: input.context || null,
|
|
207
|
+
environment: environment,
|
|
84
208
|
timestamp: timestamp,
|
|
85
209
|
text: "",
|
|
86
210
|
};
|