@spectosh/react-native 0.2.0 → 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.
Files changed (3) hide show
  1. package/README.md +5 -0
  2. package/package.json +1 -1
  3. package/src/core.js +14 -4
package/README.md CHANGED
@@ -36,6 +36,11 @@ const specto = await init({
36
36
  recording is off, or the session falls outside the sample rate, it records
37
37
  nothing.
38
38
 
39
+ New projects accept recordings from browsers only. An app sends no
40
+ browser origin, so turn off **Browsers only** in Settings → General for the
41
+ project your app records to. Until then the SDK stops and says so in the
42
+ console.
43
+
39
44
  ## Screens, users and events
40
45
 
41
46
  ```js
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spectosh/react-native",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Specto for React Native apps — screens, requests, logs, errors and custom events in the same sessions, issues and funnels as your web app. No dependencies.",
5
5
  "type": "module",
6
6
  "publishConfig": {
package/src/core.js CHANGED
@@ -14,7 +14,7 @@
14
14
  // Batches are numbered (b) per session, and a failed batch is retried with
15
15
  // the same number, so the server stores it once however often it arrives.
16
16
 
17
- export const VERSION = '0.2.0'
17
+ export const VERSION = '0.3.0'
18
18
 
19
19
  const SESSION_IDLE_MS = 30 * 60_000 // back from the background after this: a new session
20
20
  const FLUSH_MS = 5_000
@@ -45,7 +45,7 @@ const fmtArg = (a) => {
45
45
  const stripQuery = (u) => String(u).replace(/[?#].*$/, '')
46
46
 
47
47
  // The user agent the dashboard reads (device class, OS — util.js parseUA,
48
- // deviceOfUA): "SpectoRN/0.2.0 (iPhone; iOS 18.0) Shop/1.4.2"
48
+ // deviceOfUA): "SpectoRN/0.3.0 (iPhone; iOS 18.0) Shop/1.4.2"
49
49
  export function userAgentFor({ os, version, model, isPad, tablet } = {}, app = {}) {
50
50
  const ver = String(version ?? '').slice(0, 20)
51
51
  const appPart = app.name ? ` ${String(app.name).replace(/[^\w.-]/g, '')}/${String(app.version || '0').replace(/[^\w.-]/g, '')}` : ''
@@ -114,8 +114,11 @@ export function createSpecto(opts = {}) {
114
114
  if (screenPath) push('event', { t: 0, type: 'nav', path: screenPath })
115
115
  }
116
116
 
117
+ // the key in the URL too (?k=): ingest checks it before reading the body
118
+ const sendUrl = `${ingestUrl}?k=${encodeURIComponent(key)}`
119
+ let refusedCode = ''
117
120
  async function send(batch) {
118
- const res = await fetchFn(ingestUrl, {
121
+ const res = await fetchFn(sendUrl, {
119
122
  method: 'POST',
120
123
  headers: { 'Content-Type': 'text/plain' },
121
124
  body: JSON.stringify({ key, sessionId: batch.sessionId, sk: batch.sk, b: batch.b, meta: batch.meta, events: batch.events }),
@@ -125,6 +128,7 @@ export function createSpecto(opts = {}) {
125
128
  try { code = (await res.json())?.code || '' } catch { /* not json */ }
126
129
  if ((res.status === 429 && code === 'session_limit') || (res.status === 403 && code === 'session_key')) return 'rotate'
127
130
  if (res.status >= 500 || (res.status === 429 && code === 'rate_limited')) return 'retry'
131
+ refusedCode = code
128
132
  // unknown key, suspended, recording off, quota spent: stop sending
129
133
  if (res.status === 401 || res.status === 403 || (res.status === 429 && code === 'quota_exceeded')) return 'stop'
130
134
  return 'drop' // malformed or too large: this batch can never succeed
@@ -151,7 +155,13 @@ export function createSpecto(opts = {}) {
151
155
  }
152
156
  pending.shift()
153
157
  if (outcome === 'rotate' && batch.sessionId === sessionId) newSession()
154
- if (outcome === 'stop') { stop({ flush: false }); return }
158
+ if (outcome === 'stop') {
159
+ stop({ flush: false })
160
+ // a project set to "Browsers only" refuses an app (it sends no Origin):
161
+ // say how to fix it (after stop, so the console is no longer captured)
162
+ if (refusedCode === 'origin_required') { try { con?.warn?.('[specto] this project accepts recordings from browsers only, so the app is not recorded. Turn off "Browsers only" in Settings → General to record apps.') } catch { /* no console */ } }
163
+ return
164
+ }
155
165
  }
156
166
  }
157
167