@spectosh/browser 0.1.2 → 0.2.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/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "@spectosh/browser",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Specto session-replay recorder for bundler users — rrweb DOM capture, console/network/error/rage signals, privacy-masked in the browser.",
5
5
  "type": "module",
6
- "publishConfig": { "access": "public" },
7
- "repository": { "type": "git", "url": "git+https://github.com/evigasoft/specto.sh.git", "directory": "packages/browser" },
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/evigasoft/specto.sh.git",
12
+ "directory": "packages/browser"
13
+ },
8
14
  "homepage": "https://specto.sh",
9
15
  "main": "./dist/specto-browser.cjs",
10
16
  "module": "./dist/specto-browser.js",
@@ -16,17 +22,26 @@
16
22
  "./recorder": "./src/recorder.js",
17
23
  "./recorder-worker": "./src/recorder.worker.js"
18
24
  },
19
- "files": ["dist", "src", "README.md"],
25
+ "files": [
26
+ "dist",
27
+ "src",
28
+ "README.md"
29
+ ],
20
30
  "sideEffects": false,
21
31
  "scripts": {
22
32
  "build": "vite build -c vite.config.js"
23
33
  },
24
34
  "dependencies": {
25
- "rrweb": "^2.0.1"
35
+ "rrweb": "^2.1.6"
26
36
  },
27
37
  "devDependencies": {
28
- "vite": "^8.1.0"
38
+ "vite": "^8.3.1"
29
39
  },
30
- "keywords": ["session-replay", "rrweb", "analytics", "self-hosted"],
40
+ "keywords": [
41
+ "session-replay",
42
+ "rrweb",
43
+ "analytics",
44
+ "self-hosted"
45
+ ],
31
46
  "license": "MIT"
32
47
  }
package/src/index.js CHANGED
@@ -1,20 +1,51 @@
1
1
  // @spectosh/browser — the recorder for bundler users. Same capture engine as
2
2
  // the script-tag snippet; you control when it starts.
3
3
  //
4
- // import { startRecording } from '@spectosh/browser'
4
+ // import { startRecording, identify, track } from '@spectosh/browser'
5
5
  // const rec = startRecording({
6
6
  // key: 'pk_your_key',
7
7
  // endpoint: 'https://your-specto-host/api/ingest',
8
- // privacy: 'strict', // optional
8
+ // privacy: 'strict', // optional: mask all text
9
+ // sampleRate: 0.25, // optional: record a quarter of sessions
10
+ // consent: 'required', // optional: wait for grantConsent()
9
11
  // })
10
- // rec.stop() // later
11
- import { startRecording as start } from './recorder.js'
12
+ // identify('user_42', { email: 'jane@acme.io', plan: 'pro' })
13
+ // track('checkout_started', { cart: 3 })
14
+ // rec.stop()
15
+ import { startRecording as start, isOptedOut, hasConsent, scrubText, SDK_VERSION } from './recorder.js'
12
16
  import RecorderWorker from './recorder.worker.js?worker&inline'
13
17
 
18
+ let lastOpts = null
19
+
14
20
  export function startRecording(opts = {}) {
15
21
  if (!opts.endpoint) throw new Error('@spectosh/browser: opts.endpoint is required (https://<your-specto-host>/api/ingest)')
16
22
  if (!opts.key) throw new Error('@spectosh/browser: opts.key is required (your publishable pk_… key)')
23
+ lastOpts = opts
17
24
  return start({ createWorker: () => new RecorderWorker(), ...opts })
18
25
  }
19
26
 
20
- export default { startRecording }
27
+ const current = () => (typeof window !== 'undefined' ? window.__spectoRec : null)
28
+ export const identify = (id, traits) => current()?.identify(id, traits)
29
+ export const track = (name, props) => current()?.track(name, props)
30
+ export const sessionUrl = () => current()?.sessionUrl?.() || null
31
+ export const stopRecording = () => current()?.stop()
32
+
33
+ // Consent mode: record (and store anything) only after the visitor agreed.
34
+ export function grantConsent() {
35
+ try { localStorage.setItem('specto-consent', JSON.stringify('granted')) } catch { /* unavailable */ }
36
+ return lastOpts ? startRecording(lastOpts) : null
37
+ }
38
+ export function revokeConsent() {
39
+ try { localStorage.removeItem('specto-consent') } catch { /* unavailable */ }
40
+ stopRecording()
41
+ }
42
+ export function optOut() {
43
+ try { localStorage.setItem('specto-optout', 'true') } catch { /* unavailable */ }
44
+ stopRecording()
45
+ }
46
+ export function optIn() {
47
+ try { localStorage.removeItem('specto-optout') } catch { /* unavailable */ }
48
+ }
49
+
50
+ export { isOptedOut, hasConsent, scrubText, SDK_VERSION }
51
+ export default { startRecording, identify, track, sessionUrl, stopRecording, grantConsent, revokeConsent, optOut, optIn }