@daybook/feedback 1.0.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/LICENSE +21 -0
- package/README.md +279 -0
- package/dist/anchor.d.ts +24 -0
- package/dist/anchor.js +161 -0
- package/dist/breadcrumbs.d.ts +29 -0
- package/dist/breadcrumbs.js +134 -0
- package/dist/client.d.ts +61 -0
- package/dist/client.js +268 -0
- package/dist/context.d.ts +18 -0
- package/dist/context.js +74 -0
- package/dist/feedback.js +162 -0
- package/dist/files.d.ts +16 -0
- package/dist/files.js +61 -0
- package/dist/hotkey.d.ts +15 -0
- package/dist/hotkey.js +27 -0
- package/dist/index.d.ts +108 -0
- package/dist/index.js +274 -0
- package/dist/redact.d.ts +29 -0
- package/dist/redact.js +76 -0
- package/dist/screenshot.d.ts +17 -0
- package/dist/screenshot.js +69 -0
- package/dist/types.d.ts +165 -0
- package/dist/types.js +1 -0
- package/dist/widget.d.ts +81 -0
- package/dist/widget.js +535 -0
- package/package.json +46 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { PRIVATE_ATTRIBUTE } from './redact.js';
|
|
2
|
+
export async function captureScreenshot(redact) {
|
|
3
|
+
if (typeof navigator.mediaDevices?.getDisplayMedia !== 'function')
|
|
4
|
+
return null;
|
|
5
|
+
const restore = redact ? hidePrivate() : () => { };
|
|
6
|
+
let stream = null;
|
|
7
|
+
try {
|
|
8
|
+
// preferCurrentTab keeps the browser's picker on this tab where supported, so the reporter is
|
|
9
|
+
// not one misclick away from sharing a different window entirely.
|
|
10
|
+
stream = await navigator.mediaDevices.getDisplayMedia({
|
|
11
|
+
video: true,
|
|
12
|
+
audio: false,
|
|
13
|
+
// @ts-expect-error - Chromium-only hint, harmless elsewhere.
|
|
14
|
+
preferCurrentTab: true,
|
|
15
|
+
});
|
|
16
|
+
const track = stream.getVideoTracks()[0];
|
|
17
|
+
if (!track)
|
|
18
|
+
return null;
|
|
19
|
+
// A frame arrives a moment after the track opens; without this the capture is often blank.
|
|
20
|
+
await new Promise(resolve => setTimeout(resolve, 250));
|
|
21
|
+
const blob = await grabFrame(stream);
|
|
22
|
+
return blob
|
|
23
|
+
? { blob, filename: 'screenshot.png', contentType: 'image/png' }
|
|
24
|
+
: null;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// Declining the share prompt is a normal outcome, not an error worth surfacing — the report
|
|
28
|
+
// continues without a picture.
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
stream?.getTracks().forEach(track => track.stop());
|
|
33
|
+
restore();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
async function grabFrame(stream) {
|
|
37
|
+
const video = document.createElement('video');
|
|
38
|
+
video.srcObject = stream;
|
|
39
|
+
video.muted = true;
|
|
40
|
+
await video.play().catch(() => { });
|
|
41
|
+
const canvas = document.createElement('canvas');
|
|
42
|
+
canvas.width = video.videoWidth || window.innerWidth;
|
|
43
|
+
canvas.height = video.videoHeight || window.innerHeight;
|
|
44
|
+
const context = canvas.getContext('2d');
|
|
45
|
+
if (!context)
|
|
46
|
+
return null;
|
|
47
|
+
context.drawImage(video, 0, 0, canvas.width, canvas.height);
|
|
48
|
+
video.pause();
|
|
49
|
+
video.srcObject = null;
|
|
50
|
+
return new Promise(resolve => canvas.toBlob(blob => resolve(blob), 'image/png'));
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Blurs anything the host app marked private, and every password field whether it was marked or not.
|
|
54
|
+
* Returns the undo, which the caller must run — a page left permanently blurred because a capture
|
|
55
|
+
* threw would be a worse bug than the one being reported.
|
|
56
|
+
*/
|
|
57
|
+
function hidePrivate() {
|
|
58
|
+
const targets = [
|
|
59
|
+
...document.querySelectorAll(`[${PRIVATE_ATTRIBUTE}]`),
|
|
60
|
+
...document.querySelectorAll('input[type="password"]'),
|
|
61
|
+
];
|
|
62
|
+
const previous = targets.map(element => element.style.filter);
|
|
63
|
+
targets.forEach(element => { element.style.filter = 'blur(12px)'; });
|
|
64
|
+
return () => {
|
|
65
|
+
targets.forEach((element, index) => {
|
|
66
|
+
element.style.filter = previous[index] ?? '';
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The /ingest/v1 request shape. Mirrors sdk/ingest-v1/CONTRACT.md, which is frozen — these types may
|
|
3
|
+
* gain optional fields and must never lose or rename one.
|
|
4
|
+
*/
|
|
5
|
+
export interface IngestRequest {
|
|
6
|
+
idempotencyKey?: string;
|
|
7
|
+
kind?: FeedbackKind | string;
|
|
8
|
+
title?: string;
|
|
9
|
+
message: string;
|
|
10
|
+
reporter?: {
|
|
11
|
+
name?: string;
|
|
12
|
+
email?: string;
|
|
13
|
+
externalId?: string;
|
|
14
|
+
};
|
|
15
|
+
app?: {
|
|
16
|
+
version?: string;
|
|
17
|
+
build?: string;
|
|
18
|
+
environment?: string;
|
|
19
|
+
};
|
|
20
|
+
context?: Record<string, unknown>;
|
|
21
|
+
attachments?: {
|
|
22
|
+
filename: string;
|
|
23
|
+
contentType: string;
|
|
24
|
+
size: number;
|
|
25
|
+
}[];
|
|
26
|
+
/** Which surface of the product this is — a component key, e.g. "mobile-web". */
|
|
27
|
+
surface?: string;
|
|
28
|
+
}
|
|
29
|
+
/** Known values. An unknown string is accepted by the server rather than rejected. */
|
|
30
|
+
export type FeedbackKind = 'bug' | 'idea' | 'praise' | 'question';
|
|
31
|
+
export interface IngestResponse {
|
|
32
|
+
id: string;
|
|
33
|
+
reference: string;
|
|
34
|
+
attachments: {
|
|
35
|
+
id: string;
|
|
36
|
+
uploadUrl: string;
|
|
37
|
+
method: string;
|
|
38
|
+
contentType: string;
|
|
39
|
+
maxBytes: number;
|
|
40
|
+
expiresAtUtc: string;
|
|
41
|
+
/** How many declared attachments did not reach storage. Zero on a clean send. */
|
|
42
|
+
uploadsFailed?: number;
|
|
43
|
+
}[];
|
|
44
|
+
}
|
|
45
|
+
export interface Breadcrumb {
|
|
46
|
+
at: string;
|
|
47
|
+
type: 'nav' | 'click' | 'console' | 'network';
|
|
48
|
+
message: string;
|
|
49
|
+
}
|
|
50
|
+
export interface Anchor {
|
|
51
|
+
/** Null when the point could not be anchored to an element. */
|
|
52
|
+
selector: string | null;
|
|
53
|
+
/** 0..1 within the element's bounding box — not page pixels, so it survives reflow. */
|
|
54
|
+
offsetX: number;
|
|
55
|
+
offsetY: number;
|
|
56
|
+
/** Short text snapshot, so a human can find the thing after a redesign breaks the selector. */
|
|
57
|
+
elementText: string | null;
|
|
58
|
+
}
|
|
59
|
+
/** What the SDK asks at boot. */
|
|
60
|
+
export interface HandshakeRequest {
|
|
61
|
+
identity?: {
|
|
62
|
+
externalId?: string;
|
|
63
|
+
email?: string;
|
|
64
|
+
name?: string;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* HMAC-SHA256 of the identity, computed by YOUR BACKEND with the integration secret and hex
|
|
68
|
+
* encoded. Never compute this in the browser: the secret would be in the bundle, and a signature
|
|
69
|
+
* anybody can produce proves nothing.
|
|
70
|
+
*/
|
|
71
|
+
signature?: string;
|
|
72
|
+
locale?: string;
|
|
73
|
+
/** From signing in with a Daybook account. Set by the SDK, not by the host app. */
|
|
74
|
+
identityToken?: string;
|
|
75
|
+
}
|
|
76
|
+
export interface HandshakeResponse {
|
|
77
|
+
/** Null when the reporter may not file — pending approval, blocked, or anonymous under a policy. */
|
|
78
|
+
sessionToken: string | null;
|
|
79
|
+
/** Resolved from the key, so it is what this install really is rather than what it claims. */
|
|
80
|
+
environment: string;
|
|
81
|
+
reporterStatus: ReporterStatus;
|
|
82
|
+
policy: {
|
|
83
|
+
screenshots: boolean;
|
|
84
|
+
kinds: string[];
|
|
85
|
+
requireEmail: boolean;
|
|
86
|
+
maxAttachmentBytes: number;
|
|
87
|
+
};
|
|
88
|
+
/** A JSON object of typed tokens, or null. Never a stylesheet — see the widget's shadow root. */
|
|
89
|
+
theme: string | null;
|
|
90
|
+
}
|
|
91
|
+
export type ReporterStatus = 'Approved' | 'Pending' | 'Blocked' | 'Anonymous';
|
|
92
|
+
/** Widget appearance, as served by the handshake. Every field optional and every one typed. */
|
|
93
|
+
export interface FeedbackTheme {
|
|
94
|
+
accent?: string;
|
|
95
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
96
|
+
launcherLabel?: string;
|
|
97
|
+
cornerRadius?: 'none' | 'sm' | 'md' | 'lg';
|
|
98
|
+
colorScheme?: 'auto' | 'light' | 'dark';
|
|
99
|
+
}
|
|
100
|
+
export interface FeedbackOptions {
|
|
101
|
+
/** Base URL of the API, e.g. https://pm-api.hreben.us */
|
|
102
|
+
apiUrl: string;
|
|
103
|
+
/** The ingest key. Public by design; it grants only filing feedback. */
|
|
104
|
+
ingestKey: string;
|
|
105
|
+
/**
|
|
106
|
+
* Which part of the product this install is, as a component key.
|
|
107
|
+
*
|
|
108
|
+
* Optional, and the reason one key can serve a whole product instead of one key per surface. The
|
|
109
|
+
* key still decides the project and the environment — this only says which surface inside it, so
|
|
110
|
+
* the worst a wrong value does is misfile a report on your own board.
|
|
111
|
+
*/
|
|
112
|
+
surface?: string;
|
|
113
|
+
app?: {
|
|
114
|
+
version?: string;
|
|
115
|
+
build?: string;
|
|
116
|
+
environment?: string;
|
|
117
|
+
};
|
|
118
|
+
/** Known identity, when the host app has one. Entirely optional. */
|
|
119
|
+
reporter?: {
|
|
120
|
+
name?: string;
|
|
121
|
+
email?: string;
|
|
122
|
+
externalId?: string;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* The signature your backend computed for this reporter:
|
|
126
|
+
* <c>HMAC-SHA256(integrationSecret, externalId)</c>, hex.
|
|
127
|
+
*
|
|
128
|
+
* Required when the integration is set to verify identities, and worth sending whenever you can
|
|
129
|
+
* — without it we know only what the page told us, which is what anybody viewing the page could
|
|
130
|
+
* have told us too.
|
|
131
|
+
*/
|
|
132
|
+
signature?: string;
|
|
133
|
+
/**
|
|
134
|
+
* Capture a screenshot of the viewport with each report. On by default because "it looks wrong"
|
|
135
|
+
* without a picture is the single most expensive kind of report to triage.
|
|
136
|
+
*/
|
|
137
|
+
screenshots?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Mask input values, strip query strings, and blur elements marked data-daybook-private before any
|
|
140
|
+
* capture leaves the device. On by default: a screenshot contains whatever was on screen, and the
|
|
141
|
+
* server cannot undo a leak that has already crossed the wire.
|
|
142
|
+
*/
|
|
143
|
+
redact?: boolean;
|
|
144
|
+
/** Console errors, failed requests and navigation. On by default, capped and redacted. */
|
|
145
|
+
breadcrumbs?: boolean;
|
|
146
|
+
/** Keyboard shortcut to enter pick mode. Defaults to "f". Set null to disable. */
|
|
147
|
+
hotkey?: string | null;
|
|
148
|
+
/** Called after a successful report, e.g. to show your own confirmation. */
|
|
149
|
+
onSent?: (response: IngestResponse) => void;
|
|
150
|
+
/**
|
|
151
|
+
* A send that failed, or a handshake that did.
|
|
152
|
+
*
|
|
153
|
+
* The error carries a `code` — `sign_in_required`, `origin_not_allowed`, `unauthorized`. Branch on
|
|
154
|
+
* it to say something useful: under the Daybook sign-in mode the widget is absent until somebody
|
|
155
|
+
* signs in, and this is how the host knows to offer that.
|
|
156
|
+
*/
|
|
157
|
+
onError?: (error: Error) => void;
|
|
158
|
+
/**
|
|
159
|
+
* Called when the handshake comes back, with what it said.
|
|
160
|
+
*
|
|
161
|
+
* Useful for a host app that wants to explain a Pending state in its own words rather than in
|
|
162
|
+
* the widget's — or to know the widget will not appear at all, and say something instead.
|
|
163
|
+
*/
|
|
164
|
+
onReady?: (handshake: HandshakeResponse) => void;
|
|
165
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/widget.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { Anchor, FeedbackTheme, FeedbackOptions } from './types.js';
|
|
2
|
+
import { type StagedFile } from './files.js';
|
|
3
|
+
/**
|
|
4
|
+
* The reporter-facing UI, rendered inside a shadow root.
|
|
5
|
+
*
|
|
6
|
+
* The shadow root is the point. The predecessor's widgets prefixed every class with `csz-fb-` and
|
|
7
|
+
* lived in the host document, which works until a host page has a `* { box-sizing }` reset, a
|
|
8
|
+
* high-stacking-context overlay, or its own `button {}` rule — and then the feedback tool is broken on
|
|
9
|
+
* exactly the page someone is trying to report a problem on. A shadow root means host CSS cannot
|
|
10
|
+
* reach in and ours cannot leak out.
|
|
11
|
+
*/
|
|
12
|
+
export declare class FeedbackWidget {
|
|
13
|
+
private readonly options;
|
|
14
|
+
private readonly onSubmit;
|
|
15
|
+
private readonly host;
|
|
16
|
+
private readonly root;
|
|
17
|
+
private mode;
|
|
18
|
+
private anchor;
|
|
19
|
+
private detach;
|
|
20
|
+
constructor(options: FeedbackOptions, onSubmit: (input: {
|
|
21
|
+
message: string;
|
|
22
|
+
kind: string;
|
|
23
|
+
email?: string;
|
|
24
|
+
anchor: Anchor | null;
|
|
25
|
+
withScreenshot: boolean;
|
|
26
|
+
files: StagedFile[];
|
|
27
|
+
}) => Promise<string | void>);
|
|
28
|
+
/**
|
|
29
|
+
* Applies the tokens the handshake served.
|
|
30
|
+
*
|
|
31
|
+
* Custom properties on :host, never a stylesheet the server sent. The shadow root exists so the
|
|
32
|
+
* host page cannot reach in, and accepting arbitrary CSS from anywhere would hand that back —
|
|
33
|
+
* a theme is a fixed set of named values, and an unrecognised one is ignored rather than injected.
|
|
34
|
+
*/
|
|
35
|
+
setTheme(theme: FeedbackTheme | null): void;
|
|
36
|
+
private launcherLabel;
|
|
37
|
+
/**
|
|
38
|
+
* What the widget is allowed to do, from the handshake.
|
|
39
|
+
*
|
|
40
|
+
* 'pending' renders an explanation instead of a launcher: somebody who cannot report yet should
|
|
41
|
+
* be told so, not left clicking a button that silently does nothing.
|
|
42
|
+
*/
|
|
43
|
+
private state;
|
|
44
|
+
setState(state: 'ready' | 'pending'): void;
|
|
45
|
+
mount(): void;
|
|
46
|
+
unmount(): void;
|
|
47
|
+
open(): void;
|
|
48
|
+
/**
|
|
49
|
+
* Who is reporting, as of now.
|
|
50
|
+
*
|
|
51
|
+
* Held here rather than read from options, because identify() replaces the host's options object
|
|
52
|
+
* and this widget was handed the one that existed at mount — so reading options.reporter would
|
|
53
|
+
* see whoever was signed in at boot, which in a single-page app is nobody. That is the same
|
|
54
|
+
* staleness identify() was added to fix, one level further down.
|
|
55
|
+
*/
|
|
56
|
+
private reporter;
|
|
57
|
+
setReporter(reporter: FeedbackOptions['reporter']): void;
|
|
58
|
+
private render;
|
|
59
|
+
/**
|
|
60
|
+
* Shown in place of the launcher when this person is waiting on approval.
|
|
61
|
+
*
|
|
62
|
+
* Explaining beats hiding. A widget that simply is not there reads as broken to somebody who was
|
|
63
|
+
* told their company uses it, and reads as nothing at all to somebody who was not — and the
|
|
64
|
+
* second case is what Blocked gets, deliberately, by never mounting at all.
|
|
65
|
+
*/
|
|
66
|
+
private pending;
|
|
67
|
+
/** The reference of the last report, so the confirmation can quote it. */
|
|
68
|
+
private reference;
|
|
69
|
+
/**
|
|
70
|
+
* What a reporter sees after Send.
|
|
71
|
+
*
|
|
72
|
+
* Closing silently answered "did that work?" with nothing, which is the one question everybody has
|
|
73
|
+
* — and it threw away the reference the wire contract deliberately makes human-quotable. It clears
|
|
74
|
+
* itself after a few seconds rather than needing a click: an acknowledgement that has to be
|
|
75
|
+
* dismissed is a second chore for having done somebody a favour.
|
|
76
|
+
*/
|
|
77
|
+
private sent;
|
|
78
|
+
private launcher;
|
|
79
|
+
private picker;
|
|
80
|
+
private composer;
|
|
81
|
+
}
|