@spectosh/browser 0.2.4 → 0.3.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/src/scrub.js ADDED
@@ -0,0 +1,15 @@
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
+ }
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
  /**
@@ -19,6 +20,8 @@ export interface RecordingOptions {
19
20
  sampleRate?: number
20
21
  /** `'required'`: record and store nothing until `grantConsent()`. */
21
22
  consent?: 'granted' | 'required'
23
+ /** 'respect': never record visitors sending Do-Not-Track or Global Privacy Control; by default the project's setting decides */
24
+ privacySignals?: 'respect'
22
25
  /** Capture console output (default true). */
23
26
  console?: boolean
24
27
  /** Devtools-style request details: headers, sizes, timing (default true). Bodies are never captured. */
@@ -27,6 +30,12 @@ export interface RecordingOptions {
27
30
  traces?: boolean
28
31
  /** More origins to send `traceparent` to (their CORS must allow the header). */
29
32
  traceOrigins?: string[]
33
+ /** Your build's version (a git SHA or tag): bugs name the release that introduced them. */
34
+ release?: string
35
+ /** `false` leaves Point out on this page, whatever the project's settings say. */
36
+ point?: boolean
37
+ /** The "Report a problem" button on this page, over Settings → Point: false hides it. */
38
+ launcher?: LauncherOptions | false
30
39
  /** Called as events are captured. */
31
40
  onUpdate?: (info: { total: number; kind: string }) => void
32
41
  /** Called for upload outcomes (ack, drop, stop, rotate). */
@@ -73,6 +82,34 @@ export interface Recorder {
73
82
  * project's host confirms the key and its settings arrive.
74
83
  */
75
84
  export function startRecording(options: RecordingOptions): Recorder
85
+ /** The open Point, while it is open. */
86
+ export interface PointSession {
87
+ /** Send what is marked now. */
88
+ send(): Promise<void>
89
+ /** Leave without sending. */
90
+ close(): void
91
+ /** Markers placed so far. */
92
+ readonly markers: number
93
+ readonly state: 'armed' | 'marking' | 'flow' | 'sent'
94
+ }
95
+ /**
96
+ * Open Point from your own UI (a "Report a problem" menu item) — no gesture
97
+ * needed, and whoever your app shows it to may use it. Resolves with the
98
+ * open Point, or null when the project turned Point off or recording never
99
+ * started. Its code loads on first use.
100
+ */
101
+ /** Opens Point from your own UI; `via` says where from in the report ('api' by default, 'error' from an error page). */
102
+ export function openPoint(via?: 'api' | 'error'): Promise<PointSession | null> | null
103
+ export interface LauncherOptions {
104
+ position?: 'bottom-right' | 'bottom-left' | 'edge'
105
+ /** Pixels from the corner: [x, y]. CSS works too: #specto-point-entry { --specto-launcher-x / -y / -z } */
106
+ offset?: [number, number]
107
+ label?: string
108
+ /** '#RRGGBB' */
109
+ color?: string
110
+ }
111
+ /** Changes the launcher on this page (e.g. per route); false hides it. */
112
+ export function setLauncher(options: LauncherOptions | false | undefined): void
76
113
  /** Attach your user id (and a few flat traits) to the session. */
77
114
  export function identify(id: string | number, traits?: Traits): void
78
115
  /** Record a custom product event on the session's timeline. */
@@ -105,6 +142,8 @@ declare const Specto: {
105
142
  captureError: typeof captureError
106
143
  sessionUrl: typeof sessionUrl
107
144
  stopRecording: typeof stopRecording
145
+ openPoint: typeof openPoint
146
+ setLauncher: typeof setLauncher
108
147
  grantConsent: typeof grantConsent
109
148
  revokeConsent: typeof revokeConsent
110
149
  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 }> {}