@robotical/webapp-types 3.19.2 → 3.20.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.
|
@@ -2,6 +2,17 @@ import type { UserDeviceInfo } from "../../types/userDeviceInfo";
|
|
|
2
2
|
export type FeedbackRating = 1 | 2 | 3 | 4 | 5;
|
|
3
3
|
export type FeedbackSource = "emoji-modal" | "detailed-feedback" | "help-bug-report";
|
|
4
4
|
export type FeedbackAppRuntime = "phone-app" | "web-app";
|
|
5
|
+
export type FeedbackScreenshot = {
|
|
6
|
+
id: string;
|
|
7
|
+
fileName: string;
|
|
8
|
+
mimeType: string;
|
|
9
|
+
sizeBytes: number;
|
|
10
|
+
width: number;
|
|
11
|
+
height: number;
|
|
12
|
+
};
|
|
13
|
+
export type FeedbackScreenshotUpload = FeedbackScreenshot & {
|
|
14
|
+
dataUrl: string;
|
|
15
|
+
};
|
|
5
16
|
export type FeedbackEnvironment = {
|
|
6
17
|
appRuntime: FeedbackAppRuntime;
|
|
7
18
|
isPhoneApp: boolean;
|
|
@@ -21,6 +32,7 @@ export type SubmitFeedbackInput = {
|
|
|
21
32
|
context?: Record<string, unknown> | null;
|
|
22
33
|
source: FeedbackSource;
|
|
23
34
|
environment?: FeedbackEnvironment;
|
|
35
|
+
screenshots?: FeedbackScreenshotUpload[];
|
|
24
36
|
};
|
|
25
37
|
export type FeedbackRecord = {
|
|
26
38
|
rating: FeedbackRating | null;
|
|
@@ -29,6 +41,7 @@ export type FeedbackRecord = {
|
|
|
29
41
|
source: FeedbackSource;
|
|
30
42
|
context: Record<string, unknown> | null;
|
|
31
43
|
environment: FeedbackEnvironment;
|
|
44
|
+
screenshots: FeedbackScreenshot[];
|
|
32
45
|
timestamp: string;
|
|
33
46
|
text: string;
|
|
34
47
|
};
|
|
@@ -202,6 +202,9 @@ export function buildFeedbackText(record) {
|
|
|
202
202
|
if (record.rating) {
|
|
203
203
|
lines.push("Rating: ".concat(record.rating, "/5"));
|
|
204
204
|
}
|
|
205
|
+
if (record.screenshots.length > 0) {
|
|
206
|
+
lines.push("Screenshots: ".concat(record.screenshots.length, " (view in Marty Web App Insights)"));
|
|
207
|
+
}
|
|
205
208
|
lines.push("Email: ".concat(record.email || "Anonymous"));
|
|
206
209
|
if (record.message) {
|
|
207
210
|
lines.push("Message: ".concat(record.message));
|
|
@@ -209,7 +212,7 @@ export function buildFeedbackText(record) {
|
|
|
209
212
|
return lines.join("\n");
|
|
210
213
|
}
|
|
211
214
|
export function createFeedbackRecord(input) {
|
|
212
|
-
var _a, _b;
|
|
215
|
+
var _a, _b, _c;
|
|
213
216
|
var normalizedMessage = normalizeOptionalString(input.message);
|
|
214
217
|
var normalizedEmail = normalizeOptionalString(input.email);
|
|
215
218
|
var timestamp = new Date().toISOString();
|
|
@@ -221,6 +224,14 @@ export function createFeedbackRecord(input) {
|
|
|
221
224
|
source: input.source,
|
|
222
225
|
context: input.context || null,
|
|
223
226
|
environment: environment,
|
|
227
|
+
screenshots: ((_c = input.screenshots) !== null && _c !== void 0 ? _c : []).map(function (screenshot) { return ({
|
|
228
|
+
id: screenshot.id,
|
|
229
|
+
fileName: screenshot.fileName,
|
|
230
|
+
mimeType: screenshot.mimeType,
|
|
231
|
+
sizeBytes: screenshot.sizeBytes,
|
|
232
|
+
width: screenshot.width,
|
|
233
|
+
height: screenshot.height,
|
|
234
|
+
}); }),
|
|
224
235
|
timestamp: timestamp,
|
|
225
236
|
text: "",
|
|
226
237
|
};
|
|
@@ -228,11 +239,12 @@ export function createFeedbackRecord(input) {
|
|
|
228
239
|
return record;
|
|
229
240
|
}
|
|
230
241
|
export function submitFeedback(input) {
|
|
231
|
-
var _a;
|
|
242
|
+
var _a, _b;
|
|
232
243
|
return __awaiter(this, void 0, void 0, function () {
|
|
233
|
-
var requiresRobotConnection, robotConnection, record, firebaseResponse, errorText, slackDelivered, slackResponse, errorText, error_1;
|
|
234
|
-
|
|
235
|
-
|
|
244
|
+
var requiresRobotConnection, robotConnection, record, feedbackId, firebaseUpdates, _i, _c, screenshot, firebaseResponse, errorText, slackDelivered, slackResponse, errorText, error_1;
|
|
245
|
+
var _d;
|
|
246
|
+
return __generator(this, function (_e) {
|
|
247
|
+
switch (_e.label) {
|
|
236
248
|
case 0:
|
|
237
249
|
requiresRobotConnection = isRobotConnectionRequiredForFeedbackSource(input.source);
|
|
238
250
|
robotConnection = requiresRobotConnection
|
|
@@ -243,27 +255,35 @@ export function submitFeedback(input) {
|
|
|
243
255
|
}
|
|
244
256
|
record = createFeedbackRecord(__assign(__assign({}, input), { context: robotConnection
|
|
245
257
|
? __assign(__assign({}, ((_a = input.context) !== null && _a !== void 0 ? _a : {})), robotConnection) : input.context }));
|
|
246
|
-
|
|
258
|
+
feedbackId = randomHashGenerator();
|
|
259
|
+
firebaseUpdates = (_d = {},
|
|
260
|
+
_d[feedbackId] = record,
|
|
261
|
+
_d);
|
|
262
|
+
for (_i = 0, _c = (_b = input.screenshots) !== null && _b !== void 0 ? _b : []; _i < _c.length; _i++) {
|
|
263
|
+
screenshot = _c[_i];
|
|
264
|
+
firebaseUpdates["~screenshots/".concat(feedbackId, "/").concat(screenshot.id)] = screenshot.dataUrl;
|
|
265
|
+
}
|
|
266
|
+
return [4 /*yield*/, fetch("".concat(WEB_APP_FEEDBACK_DB_URL, ".json?print=silent"), {
|
|
247
267
|
method: "PATCH",
|
|
248
268
|
headers: {
|
|
249
269
|
Application: "application/json",
|
|
250
270
|
"Content-Type": "application/json",
|
|
251
271
|
},
|
|
252
|
-
body: JSON.stringify(
|
|
272
|
+
body: JSON.stringify(firebaseUpdates),
|
|
253
273
|
})];
|
|
254
274
|
case 1:
|
|
255
|
-
firebaseResponse =
|
|
275
|
+
firebaseResponse = _e.sent();
|
|
256
276
|
if (!!firebaseResponse.ok) return [3 /*break*/, 3];
|
|
257
277
|
return [4 /*yield*/, firebaseResponse.text()];
|
|
258
278
|
case 2:
|
|
259
|
-
errorText =
|
|
279
|
+
errorText = _e.sent();
|
|
260
280
|
Logger.error(SHOW_LOGS, TAG, "Failed to submit feedback to Firebase: ".concat(firebaseResponse.status, " ").concat(errorText));
|
|
261
281
|
throw new Error("Failed to submit feedback");
|
|
262
282
|
case 3:
|
|
263
283
|
slackDelivered = true;
|
|
264
|
-
|
|
284
|
+
_e.label = 4;
|
|
265
285
|
case 4:
|
|
266
|
-
|
|
286
|
+
_e.trys.push([4, 8, , 9]);
|
|
267
287
|
return [4 /*yield*/, fetch(WEB_APP_FEEDBACK_SLACK_WEBHOOK_URL, {
|
|
268
288
|
method: "POST",
|
|
269
289
|
headers: {
|
|
@@ -272,15 +292,15 @@ export function submitFeedback(input) {
|
|
|
272
292
|
body: JSON.stringify({ text: record.text }),
|
|
273
293
|
})];
|
|
274
294
|
case 5:
|
|
275
|
-
slackResponse =
|
|
295
|
+
slackResponse = _e.sent();
|
|
276
296
|
if (!!slackResponse.ok) return [3 /*break*/, 7];
|
|
277
297
|
return [4 /*yield*/, slackResponse.text()];
|
|
278
298
|
case 6:
|
|
279
|
-
errorText =
|
|
299
|
+
errorText = _e.sent();
|
|
280
300
|
throw new Error("Failed Slack response: ".concat(slackResponse.status, " ").concat(errorText));
|
|
281
301
|
case 7: return [3 /*break*/, 9];
|
|
282
302
|
case 8:
|
|
283
|
-
error_1 =
|
|
303
|
+
error_1 = _e.sent();
|
|
284
304
|
slackDelivered = false;
|
|
285
305
|
Logger.error(SHOW_LOGS, TAG, "Failed to submit feedback to Slack", error_1);
|
|
286
306
|
return [3 /*break*/, 9];
|