@spectosh/browser 0.2.5 → 0.3.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/src/scrub.js ADDED
@@ -0,0 +1,28 @@
1
+ // Free text the app itself produces (console lines, error messages, what
2
+ // Point reads off the page) can carry PII. Redact the shapes that are never
3
+ // useful for debugging. Shared by the recorder and Point.
4
+ const TEXT_SCRUBBERS = [
5
+ [/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi, '[email]'],
6
+ [/\beyJ[\w-]{6,}\.[\w-]{6,}\.[\w-]{6,}\b/g, '[jwt]'],
7
+ [/\b(Bearer|Basic)\s+[\w.~+/=-]{8,}/gi, '$1 [token]'],
8
+ [/\b(?:\d[ -]?){13,19}\b/g, '[number]'], // card / account numbers
9
+ [/\b(sk|pk|rk)_(live|test)_[\w]{8,}\b/g, '[key]'],
10
+ ]
11
+ export function scrubText(s) {
12
+ let out = String(s ?? '')
13
+ for (const [re, rep] of TEXT_SCRUBBERS) out = out.replace(re, rep)
14
+ return out
15
+ }
16
+
17
+ // Strict privacy masks every text on the page. The site can show the text of
18
+ // elements it has checked: `specto-unmask` / `data-specto-unmask` in its
19
+ // markup, or the project's selector list (Settings → Privacy & masking).
20
+ // Never inside `specto-mask` / `specto-block`, never a form field, and what
21
+ // shows is still scrubbed (above). An invalid selector shows nothing.
22
+ export const UNMASK = '.specto-unmask,[data-specto-unmask]'
23
+ export function showsText(el, extra) {
24
+ try {
25
+ if (!el || !el.closest || el.closest('.specto-mask,.specto-block')) return false
26
+ return Boolean(el.closest(UNMASK) || (extra && el.closest(extra)))
27
+ } catch { return false }
28
+ }
package/types/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- // Types for @spectosh/browser — the Specto session-replay recorder.
1
+ // Types for @spectosh/browser — the Specto recorder (session replay) and
2
+ // Point, the cursor mode people use to mark what is broken.
2
3
 
3
4
  export interface RecordingOptions {
4
5
  /**
@@ -15,10 +16,14 @@ export interface RecordingOptions {
15
16
  configUrl?: string | false
16
17
  /** `'strict'` masks all text (inputs are always masked) and keeps only the path of URLs. */
17
18
  privacy?: 'balanced' | 'strict'
19
+ /** Under strict privacy, a CSS selector list whose text is shown (still scrubbed of emails and card-like numbers), e.g. `'nav, .price'`. Also the `specto-unmask` class. */
20
+ unmask?: string
18
21
  /** Fraction of sessions recorded, decided once per session (0–1). */
19
22
  sampleRate?: number
20
23
  /** `'required'`: record and store nothing until `grantConsent()`. */
21
24
  consent?: 'granted' | 'required'
25
+ /** 'respect': never record visitors sending Do-Not-Track or Global Privacy Control; by default the project's setting decides */
26
+ privacySignals?: 'respect'
22
27
  /** Capture console output (default true). */
23
28
  console?: boolean
24
29
  /** Devtools-style request details: headers, sizes, timing (default true). Bodies are never captured. */
@@ -27,6 +32,12 @@ export interface RecordingOptions {
27
32
  traces?: boolean
28
33
  /** More origins to send `traceparent` to (their CORS must allow the header). */
29
34
  traceOrigins?: string[]
35
+ /** Your build's version (a git SHA or tag): bugs name the release that introduced them. */
36
+ release?: string
37
+ /** `false` leaves Point out on this page, whatever the project's settings say. */
38
+ point?: boolean
39
+ /** The "Report a problem" button on this page, over Settings → Point: false hides it. */
40
+ launcher?: LauncherOptions | false
30
41
  /** Called as events are captured. */
31
42
  onUpdate?: (info: { total: number; kind: string }) => void
32
43
  /** Called for upload outcomes (ack, drop, stop, rotate). */
@@ -73,6 +84,34 @@ export interface Recorder {
73
84
  * project's host confirms the key and its settings arrive.
74
85
  */
75
86
  export function startRecording(options: RecordingOptions): Recorder
87
+ /** The open Point, while it is open. */
88
+ export interface PointSession {
89
+ /** Send what is marked now. */
90
+ send(): Promise<void>
91
+ /** Leave without sending. */
92
+ close(): void
93
+ /** Markers placed so far. */
94
+ readonly markers: number
95
+ readonly state: 'armed' | 'marking' | 'flow' | 'sent'
96
+ }
97
+ /**
98
+ * Open Point from your own UI (a "Report a problem" menu item) — no gesture
99
+ * needed, and whoever your app shows it to may use it. Resolves with the
100
+ * open Point, or null when the project turned Point off or recording never
101
+ * started. Its code loads on first use.
102
+ */
103
+ /** Opens Point from your own UI; `via` says where from in the report ('api' by default, 'error' from an error page). */
104
+ export function openPoint(via?: 'api' | 'error'): Promise<PointSession | null> | null
105
+ export interface LauncherOptions {
106
+ position?: 'bottom-right' | 'bottom-left' | 'edge'
107
+ /** Pixels from the corner: [x, y]. CSS works too: #specto-point-entry { --specto-launcher-x / -y / -z } */
108
+ offset?: [number, number]
109
+ label?: string
110
+ /** '#RRGGBB' */
111
+ color?: string
112
+ }
113
+ /** Changes the launcher on this page (e.g. per route); false hides it. */
114
+ export function setLauncher(options: LauncherOptions | false | undefined): void
76
115
  /** Attach your user id (and a few flat traits) to the session. */
77
116
  export function identify(id: string | number, traits?: Traits): void
78
117
  /** Record a custom product event on the session's timeline. */
@@ -105,6 +144,8 @@ declare const Specto: {
105
144
  captureError: typeof captureError
106
145
  sessionUrl: typeof sessionUrl
107
146
  stopRecording: typeof stopRecording
147
+ openPoint: typeof openPoint
148
+ setLauncher: typeof setLauncher
108
149
  grantConsent: typeof grantConsent
109
150
  revokeConsent: typeof revokeConsent
110
151
  optOut: typeof optOut
package/types/react.d.ts CHANGED
@@ -37,8 +37,10 @@ export function useSpecto(): SpectoApi
37
37
  export interface SpectoErrorBoundaryProps {
38
38
  children?: ReactNode
39
39
  /** Shown instead of the children after an error; or a render function. */
40
- fallback?: ReactNode | ((args: { error: unknown; reset: () => void }) => ReactNode)
40
+ fallback?: ReactNode | ((args: { error: unknown; reset: () => void; report: () => void }) => ReactNode)
41
41
  onError?: (error: unknown, info: ReactErrorInfo) => void
42
+ /** A "Show us what happened" button under the fallback that opens Point; a string sets its label. */
43
+ reportButton?: boolean | string
42
44
  }
43
45
  /** Reports what it catches — with the component stack — to Specto. */
44
46
  export class SpectoErrorBoundary extends Component<SpectoErrorBoundaryProps, { error: unknown }> {}